Here is a python code snippet that takes the current time (in UTC), converts it to a formatted string and parses the string. I would like to get the same timestamp, but I get a different timestamp because of the time zone I am in.
How can I reconstruct the same time stamp as I started with?
#!/usr/bin/env python3
import time
from datetime import datetime
TIME_FORMAT='%Y-%m-%d %H:%M:%S'
ts = int(time.time()) # UTC timestamp
timestamp = datetime.utcfromtimestamp(ts).strftime(TIME_FORMAT)
d1 = datetime.strptime(timestamp, TIME_FORMAT)
ts1 = int(d1.strftime("%s"))
print("Time as string : %s" % d1)
print("Source timestamp : %d" % ts)
print("Parsed timestamp : %d" % ts1)
Output:
Time as string : 2018-12-06 00:47:32
Source timestamp : 1544057252
Parsed timestamp : 1544086052