PYnative

Python Programming

  • Learn Python
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises
    • Python Exercises
    • C Programming Exercises
    • C++ Exercises
  • Quizzes
  • Code Editor
    • Online Python Code Editor
    • Online C Compiler
    • Online C++ Compiler
Home » Python » Python DateTime » Timestamp In Python

Timestamp In Python

Updated on: December 5, 2021 | 2 Comments

Python provides various libraries to work with timestamp data. For example, the datetime and time module helps in handling the multiple dates and time formats. In addition to this, it supports various functionalities involving the timestamp and timezone.

After reading this tutorial, you’ll learn: –

  • How to get the curent timestamp in Python
  • Convert timestamp to a datetime
  • Convert datetime to timestamp
  • Format timestamp to string object and vice-versa
  • How to get the timestamp object with an offset into a date-time object.

Table of contents

  • What is Timestamp in Python
  • Get Current Timestamp
    • Datetime to Timestamp
    • Get Timestamp Using time Module
    • Get Timestamp Using calendar Module
  • Convert Timestamp to Datetime (format)
  • Convert Timestamp to String
  • Get Timestamp in Milliseconds
  • Get The UTC timestamp
  • Timestamp from datetime with a Different Timezone
  • Convert an Integer Timestamp to Datetime

What is Timestamp in Python

A timestamp is encoded information generally used in UNIX, which indicates the date and time at which a particular event has occurred. This information could be accurate to the microseconds. It is a POSIX timestamp corresponding to the datetime instance.

In general, the date and time data are saved in the UNIX timestamp format. A UNIX time or Epoch or POSIX time is the number of seconds since the Epoch.

Unix time (also known as Epoch time, POSIX time, seconds since the Epoch, or UNIX Epoch time) describes a point in time.

It is the number of seconds that have elapsed since the Unix epoch, minus leap seconds.

The Unix epoch is 00:00:00 UTC on 1 January 1970 (an arbitrary date); leap seconds are ignored, with a leap second having the same Unix time as the second before it, and every day is treated as if it contains exactly 86400 seconds.

Wikipedia.

The reason we are using the UNIX epoch time as 1 January 1970 is because of the fact that UNIX came into business around that time frame.

The below image shows how a particular date and time is represented in different formats.