I have the input as a Unix timestamp, which is generated according to UTC time. I need to convert it to human readable time and then adjust the time zones, which is +02:00.
Using the datetime library, I have tried:
from datetime import datetime
import pytz
time = "1657893300324"
logtime = datetime.utcfromtimestamp(int(time)/1000).isoformat(sep=',', timespec='milliseconds')
timezone = pytz.timezone('Europe/Berlin')
d_aware = timezone.localize(int(logtime))
print(d_aware)
error thrown in this process:
ValueError: invalid literal for int() with base 10: '2022-07-15,13:55:00.324'
Another method:
from datetime import datetime
from datetime import timedelta
time = "1657893300324"
logtime = datetime.utcfromtimestamp(int(time)/1000).isoformat(sep=',', timespec='milliseconds')
two_hrs = datetime.timedelta(hours=2)
local_time = logtime + two_hrs
print(local_time)
error thrown:
AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'