0

My goal is to convert UTM to local time and then to Unix time. This is the original time:

import pandas as pd
pd.to_datetime(nw_pd_file['datetime(utc)'][0],format='%Y-%m-%d %H:%M:%S')
Timestamp('2019-04-26 21:38:11')

Adding utc info

>>> pd.to_datetime(nw_pd_file['datetime(utc)'][0],format='%Y-%m-%d %H:%M:%S').tz_localize('UTC')
Timestamp('2019-04-26 21:38:11+0000', tz='UTC')

converting to local Alaska time:

>>> pd.to_datetime(nw_pd_file['datetime(utc)'][0],format='%Y-%m-%d %H:%M:%S').tz_localize('UTC').tz_convert(pytz.timezone("America/Anchorage"))
Timestamp('2019-04-26 13:38:11-0800', tz='America/Anchorage')

Up to here all is good. But when I convert the correct local time to unix time, the restul is in UTC and not in Alaska local time:

>>>pd.to_datetime(nw_pd_file['datetime(utc)'][0],format='%Y-%m-%d %H:%M:%S').tz_localize('UTC').tz_convert(local).timestamp()
1556314691.0

When it should be

1556314691.0-8*3600=1556285891.0 # 8 for eight hours Alaska daylight time.

In fact, I get the same Unix timestamp independent of the time-zone:

>>> pd.to_datetime(nw_pd_file['datetime(utc)'][0],format='%Y-%m-%d %H:%M:%S').tz_localize('UTC').timestamp()
1556314691.0

Is the timestamp() meothod cannot read the timezone correctly?

thanks

1 Answer 1

1

The UNIX timestamp is designed to be timezone independent. See this thread Do unix timestamps change across timezones?

Your code convert the same time to two different time zones, but their UNIX timestamps remain the same.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.