How to get the current date/time in Python
The standard way to get the current date/time is to use the datetime.today (opens new window) method from the datetime (opens new window) module which will return the current local date and time. You can then access year
, month
, day
, hour
, minute
, second
, microsecond
and tzinfo
. You can also use strftime (opens new window) to format the datetime
object into any string format.
Python
Copy code