xxxxxxxxxx
import time
# Get current timestamp in seconds since the epoch
timestamp = time.time()
print(timestamp)
xxxxxxxxxx
import datetime
current_timestamp = datetime.datetime.now().timestamp()
print(current_timestamp)
xxxxxxxxxx
import time
ts = time.time()
// OR
import datetime;
ct = datetime.datetime.now()
ts = ct.timestamp()
xxxxxxxxxx
from datetime import datetime
# Returns a datetime object containing the local date and time
dateTimeObj = datetime.now()
print(dateTimeObj)
# Output
# 2018-11-18 09:32:36.435350
xxxxxxxxxx
# using time module
import time
# ts stores the time in seconds
ts = time.time()
# print the current timestamp
print(ts)
xxxxxxxxxx
# import the date class
from datetime import datetime
# Getting Datetime from timestamp
date_time = datetime.fromtimestamp(1434323424)
print("Datetime from timestamp:", date_time)