2
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

5
  • 4
    Isn't it an UTC issue? Commented May 15, 2021 at 18:09
  • 1
    Seems like your in another time zone than UTC. Commented May 15, 2021 at 18:12
  • 1
    Converting the timezone to Asia/Calcutta gives the expected output. Commented May 15, 2021 at 18:19
  • how to convert timezone to Asia/Kolkata Commented May 15, 2021 at 18:53
  • 1
    For Asia/Kolkata just change the tz_convert to tz_convert('Asia/Kolkata') Commented May 15, 2021 at 19:33

2 Answers 2

1

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')
Sign up to request clarification or add additional context in comments.

2 Comments

using tz_convert showing this error 'NoneType' object has no attribute 'tz_convert'
Did you use the entire code above? Also, can you share the version of pandas you’re using with print(pd.__version__)
0
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')

Comments

Your Answer

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