Python Timestamp Examples with Time Module – POFTUT

Python Timestamp Examples with Time Module

Timestamp is used to hold the seconds from epoch. Epost is a generic term used to represent data January 1st, 1970 in UTC. So this means epoch and timestamp do not have any time zone or by default UTC time zone. In this tutorial we will look different examples about time  module with time stamp examples.

Import Time Module

As related functions are provided by modules we need to import time  module in order to use time() function. We will use classical python import to load.

Get Timestamp with time() Function

We will use time()  function in order to create a timestamp for the current time. We will assign created timestamp into variable named ts and then print with print()  function like below.

Get Timestamp with time() Function

Get Timestamp with time() Function

Get Timestamp with gmtime() Function

In this example we will use datetime  module and now() function in order to We will print is with print() function. We have to import datetime module before running now() function.

Get Timestamp with gmtime() Function

Get Timestamp with gmtime() Function

Get Timestamp with Calender Module

We have alternatives while getting current time stamp. But most of them are related with time  module. We will use timegm()  function like below.

Get Timestamp with Calender Module

Get Timestamp with Calender Module

LEARN MORE  How To Use vmstat To Monitor Linux Performance

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)