>>> from datetime import datetime
>>> ts = int("1284101485")
# if you encounter a "year is out of range" error the timestamp
# may be in milliseconds, try `ts /= 1000` in that case
>>> print(datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
#'%Y' will be replaced by the year '%m' by the month '%d; by the day and so on
#You move these how you want in the string, other characters will be ignored!
... '2010-09-10 06:51:25'
#get date from unix timestamp
from datetime import date
timestamp = date.fromtimestamp(1326244364)
from datetime import datetime
# current date and time
currentDateTime = datetime.now()
print("Current Date Time is ", currentDateTime)
# convert datetime to timestamp
timestamp = datetime.timestamp(currentDateTime)
print("Current Unix Timestamp is ", timestamp)
# importing datetime module
import datetime
import time
# assigned regular string date
date_time = datetime.datetime(2021, 7, 26, 21, 20)
# print regular python date&time
print("date_time =>",date_time)
# displaying unix timestamp after conversion
print("unix_timestamp => ",
(time.mktime(date_time.timetuple())))
from datetime import datetime, timedelta
import time
dtime = datetime.now() + timedelta(seconds=3)
unixtime = time.mktime(dtime.timetuple())