There are two ways you can get the current time in python.
- using the
datetimeobject - using the
timemodule
Using the datetime object
First, you need to import the datetime module. Then by calling the now method, you can create a datetime object containing the current date and time.
This will output:
Using the strftime you can convert the datetime to a string by specifying the format.
Using the time module
First, import the time module, then call the localtime method to create a time object.
Using the strftime you can convert the time to a string by specifying the format.
Got an article suggestion?
Let us know
BY
NC
SA
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.