Seconds from era to relative date

I have been working with dates from the era and have already received, for example:

date = 6928727.56235

I would like to convert this to another relative format so that I can convert this to something relative to the era.

Using time.gmtime (date), it returned

year=1970, mon=3, day=22, hour=4, min=38, sec=47

I think the era starts at '01 / 01/1970 00:00:00 ', so the method should return a relative date something like this:

'2 months 21 days 04:38:47'

Anything that helps?

+7
source share
4 answers
from datetime import timedelta

a = timedelta(seconds=6928727.56235)

# a is now datetime.timedelta(80, 16727, 562350)

print "%d days %02d:%02d:%02d" % (a.days, a.seconds / 3600, (a.seconds / 60) % 60, a.seconds % 60)

Returns 80 days 04:38:47what is correct, but not quite what the OP requires (80 days instead of 2 months 21 days).

+4
source

- : '2 22 04:38:47'

, 28 31 . "2 22 " - 81 84 . ( 78 84 , ).

. , , , , ( ).

, " ", "80 ", " ". " " " 20 ". .

eumiros

timedelta(seconds=6928727.56235)

, .

(, , , .:))

+5

time.gmtime ParseTuple, . -

>>> time_epoch = time.gmtime(0)
>>> time_at_hand = time.gmtime(6928727.56235)
>>> print "It been %d days somewhat like  %d months, %d days and %d hours, %d  minutes, %d seconds " % (time_at_hand.tm_yday - time_epoch.tm_yday, time_at_hand.tm_mon - time_epoch.tm_mon , time_at_hand.tm_mday - time_epoch.tm_mday, time_at_hand.tm_hour - time_epoch.tm_hour, time_at_hand.tm_min - time_epoch.tm_min, time_at_hand.tm_sec - time_epoch.tm_sec)
It been 80 days somewhat like  2 months, 21 days and 4 hours, 38  minutes, 47 seconds 
+1

Eumiro Answer, 60 .. Pandas .

date = 6928727.56235
import pandas as pd
pd.Timestamp(datetime.fromtimestamp(date))-pd.Timestamp(datetime.fromtimestamp(0))

Timedelta('80 days 04:38:47.562350')
0

All Articles