I have a timestamp in string format
timestamp_str = '18:02:19 14:14:11 465872'
format_str = '%y:%m:%d %H:%M:%S %f'
and to convert it to UTC in UNIX I have written the following code
def str2utc(timestr,formatstr):
timeobj = datetime.datetime.strptime(timestr, formatstr)
time_utc = time.mktime(timeobj.timetuple())
return time_utc
timestamp_utc_unix = str2utc(timestamp_str,format_str)
Nevertheless, as I already know, this does not work if my system time is something else than utc. I have read other posts like
Python strptime() and timezones?
but just cannot wrap my head around how to correct it. How do I have to change the code so that not matter what my system time is it always outputs utc in unix?