How to get the current date/time in Python

The standard way to get the current date/time is to use the (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.

Copy code

Join our community

Your sign-up could not be saved. Please try again.
Your sign-up was successful.

Sign-up and get tips to becoming a software engineer.