0

The time_orign_epoch,should be 1970-01-01 00:00:00,why i am getting 5:30 more?

time_origin_epoch = datetime.datetime.fromtimestamp(0)
print time_origin_epoch
1970-01-01 05:30:00
Shiva Rama Krishna
  • 365
  • 2
  • 4
  • 14

2 Answers2

2

It's because you live in India!

How did I know that?

Well, a timestamp of 0 means 1970-01-01 00:00:00 UTC. Since your output shows 05:30:00, your time zone is UTC+05:30. And India is one of the few places in the world with a timezone offset which is not a whole number of hours.

When you construct a datetime in Python using fromtimestamp(), the default is to use your local timezone for the conversion. This corresponds to calling the classic C function localtime() rather than gmtime().

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
0

Running your code gives me a result that is five hours behind what it should be. This is consistent with the fact that I am in EST and am five hours behind UTC. If you are simply looking to confirm correct output, then check your time zone, I would guess you are somewhere in Eastern Asia. However, if you need a zeroes value produced by the program itself, try resetting your timezone to UTC from the program, and running that snippet again.

From this answer:

If you are using Unix, you can use time.tzset to change the process's local timezone:

import os
import time
os.environ['TZ'] = tz
time.tzset()

You could then convert the datetime strings to NumPy datetime64's using

def using_tzset(date_strings, tz):
    os.environ['TZ'] = tz
    time.tzset()
    return np.array(date_strings, dtype='datetime64[ns]')
Joseph Farah
  • 2,463
  • 2
  • 25
  • 36