2

I have an list of timestamps in the form of seconds since January 1, 1999 00:00 UTC (not epoch). I am looking for a way to convert this to a date/time in a more standard format (like YYYY-MM-DD HH:MM:SS UTC). I'm not sure how to do this since its not that more usual "seconds since epoch" format.

Thanks.

randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72
hm8
  • 1,381
  • 3
  • 21
  • 41
  • It should be pretty easy to convert to a "seconds since epoch" since it's just a constant offset of 915177600 seconds... – mgilson Nov 16 '16 at 18:50

2 Answers2

1

Figured it out with some simple datetime and timedelta stuff

d0 = datetime(1999,1,1,0,0,0)
dt = timedelta(seconds = time[0])
d  = d0 + dt 

>>> d
datetime.datetime(2016, 8, 19, 13, 28, 55, 317013)
hm8
  • 1,381
  • 3
  • 21
  • 41
1

I'm not pretty sure about what do you need exactly, but I hope that this can help you:

x = datetime.datetime(1999,1,1)
y=x + datetime.timedelta(0,1256083200.0)
print('{:%Y-%m-%d %H:%M:%S}'.format(y))
#print:'2038-10-21 00:00:00'

Reference:

What is the standard way to add N seconds to datetime.time in Python?

How to convert a Python datetime object to seconds

How can I create basic timestamps or dates? (Python 3.4)

Community
  • 1
  • 1
Cyberguille
  • 1,552
  • 3
  • 28
  • 58