Home  »  CodeSnippets   »   How to get Current Date and Time in Python

How to get Current Date and Time in Python

Posted: February 6, 2022 | by Site Host

Using DateTime to print date and time:

from datetime import datetime
now = datetime.now()
print("date and time now: ", now)

#formtat the output
print (now.strftime("%Y-%m-%d %H:%M:%S"))

Output: 2022-01-19 11:24:32

Using date:

from datetime import date

today = date.today()
print("Today's date:", today)

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Share it!

See also  PHP Remove Last Element From Array