What is a classy way to store date and time information in a float in python with millisecond precision? Edit: I'm using python 2.7
I've hacked together the following:
DT = datetime.datetime(2016,01,30,15,16,19,234000) #trailing zeros are required
DN = (DT - datetime.datetime(2000,1,1)).total_seconds()
print repr(DN)
Output:
507482179.234
And then to revert back to datetime:
DT2 = datetime.datetime(2000,1,1) + datetime.timedelta(0, DN)
print DT2
Output:
2016-01-30 15:16:19.234000
But I'm really looking for something a little more classy and robust.
In matlab I would use the datenum
and datetime
functions:
DN = datenum(datetime(2016,01,30,15,16,19.234))
And to revert back:
DT = datetime(DN,'ConvertFrom','datenum')