Reputation:
unix_timestamp=1284105682
print(pd.to_datetime(unix_timestamp,unit='s',origin='unix'))
Expected Output : 2010-09-10 13:31:22 My Output: 2010-09-10 08:01:22
I am unable to figure out how time is getting wrong
Upvotes: 2
Views: 116
Reputation: 5918
unix_timestamp=1284105682
pd.to_datetime(unix_timestamp,unit='s', utc=True).tz_convert('Asia/Kolkata')
Output
Timestamp('2010-09-10 13:31:22+0530', tz='Asia/Kolkata')
Upvotes: 0
Reputation: 351
It seems to be a UTC-related issue. You can create the datetime with UTC and then change it to your time-zone like this:
import pandas as pd
unix_timestamp=1284105682
df = pd.to_datetime(unix_timestamp, unit='s', origin='unix', utc=True)
df.tz_convert('America/Sao_Paulo')
Upvotes: 1