I have an array of Unix Epoch time stampts that I need to convert to datetime format in python.
I can make the conversion ok using numpy and pandas, as below:
tim = [1627599600,1627599600,1627599601,1627649998,1627649998,1627649999]
tim_np = np.array(tim)
tim_np = np.asarray(tim, dtype='datetime64[s]',)
tim_pd = pd.to_datetime(tim,unit='s', utc=True,)
print(tim_np)
print(tim_pd)
The problem I am running into is that the time zone is wrong, I am in NY so require it set to "EST".
I tried addressing by setting utc=True
in the pd.to_datetime
function but it still keeps defaulting to "GMT" ( 5 hours ahead).
I also tried the datetime.fromtimestamp(0)
but it seemingly only works on single elements and not arrays - https://note.nkmk.me/en/python-unix-time-datetime/
Is there any efficient method to set the time zone when converting epochs?