Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

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.