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.
ts = time.time()
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
ts = datetime.datetime.now().timestamp()
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.
ts = calendar.timegm(time.gmtime())