- UTC timestamps are useful to order events (log data) and calculate time difference, in terms of elapsed time. A naive approach to getting a timestamp in python might go like: # define epoch, the.
- Getting the UTC timestamp Use the datetime.datetime.now to get the current date and time. Then use tzinfo class to convert our datetime to UTC. Lastly, use the timestamp to convert the datetime object, in UTC, to get the UTC timestamp.
Python Timezone Utc
I’ve explained what UTC is and how it allows us to define dates and times, but countries like to have their wall time noon match with the solar time for noon, so the sun is at the top of the sky at 12 PM. That is why UTC defines offsets, so we can have 12 AM with an offset of +4 hours from UTC.
Sample output of above program.
Time in MST: 2017-01-19 06:06:14.495605-07:00
Time in EST: 2017-01-19 08:06:14.496606-05:00
Time in UTC: 2017-01-19 13:06:14.496606+00:00
Time in GMT: 2017-01-19 13:06:14.496606+00:00
Time in HST: 2017-01-19 03:06:14.497606-10:00