How can I return the current time of the local machine?
now() is used to get the present time. The timetuple() is a method of datetime class that returns the attributes of datetime as a name tuple. To get the timestamp of 13 digits it has to be multiplied by 1000.
We can convert the timestamp back to datetime object using the fromtimestamp() method that is available in the datetime module. It returns the local date and time corresponding to the POSIX timestamp, such as is returned by time. time() .
To get the current time in particular, you can use the strftime() method and pass into it the string ”%H:%M:%S” representing hours, minutes, and seconds.
Getting the UTC timestampUse the datetime. datetime. now() to get the current date and time. Then use tzinfo class to convert our datetime to UTC.
Do you mean this: time.time()?
From the docs:
Return the time as a floating point number expressed in seconds since the epoch, in UTC
>>> import time
>>> time.time()
1269884900.480978
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With