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