Working With Unix Time
00:00 Unix time is an international system, which is used to represent time as an ever-growing number in seconds. The reason why Unix time is important to know is because the majority of computer systems use Unix time as a way to represent time internally.
00:13 Unix time began on January 1, 1970, at exactly midnight UTC time. This is formally known as the Unix epoch. Because of this, you might also hear Unix time referred to as epoch time.
00:25 One of the main benefits of Unix time is that it’s unambiguous. Regardless of the time zone, it cannot be offset.
00:33
If you want to see what the current Unix time is, you can use the .timestamp()
method after importing the datetime
module and creating your datetime
object.
00:41
Here you can see me calling my datetime
object, now
, followed by the .timestamp()
method. As you can see, the .timestamp()
method returns a very long number.
00:51 This is the exact amount of seconds that have passed since January 1, 1970, at midnight UTC time, the Unix epoch.
01:00
You now know about Unix time and how to use it in Python. When working with timestamps in Python, you want them to be unambiguous and precise. And while it’s important to know about Unix time, in real-world applications, you’re likely better off making your datetime
objects time zone–aware, as doing so allows your timestamps to be both unambiguous as well as readable to humans.
01:20
In the next lesson, I’ll show you how to create and work with time zone–aware datetime
objects.
Become a Member to join the conversation.