Unix Timestamp, UTC And Their Conversions In Python!
Recently I started messing with Nidaba. Nidaba is a data analytics project devoted to analysing and making use of the freely available information on Stack Overflow, in particular when relating to the Python programming language. SO gives all time objects in Unix time format. For analysis, it is required to convert it into human readable format to figure out the day it corresponds to. Let us take a look at UTC & Unix timestamps.
Coordinated Universal Time(UTC):
It is the primary time standard by which the world regulates clocks and time.
To get current UTC time in Python, You can use datetime module.
Unix time / POSIX time / Epoch time:
It is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds.
To get Unix timestamp, you can use time module.
If You are using Pyhon 3.4, you can use timestamp function to convert it
To convert Unix timestamp to UTC You can use utcfromtimestamp function.
To convert UTC time object to Unix time, you can use strftime function.
Alternatively You can use calendar.timegen function also.
I am Chillar Anand. I daydream a lot and write about the things that interest me here. You can read more about this blog here.