Using Python, I'm storing a date & time as datetime.datetime into GAE. Is there a way to get the value of the date time in milliseconds as opposed to the fully formatted string version?
Based on the docs for datetime.datetime, I don't see any native methods on the date time class that does this. http://docs.python.org/release/2.5.2/lib/datetime-datetime.html
The original date value is stored this way:
date_time_float = 1015182600 #some date as timestamp
date_time_object = datetime.fromtimestamp(date_time_float);
When I pull the data from the store, it is of type:
type(exported_date_time) # type: datetime.datetime
There's strftime to convert into a string representation but what I'm looking for is to convert 'exported_date_time' to milliseconds.
To get the seconds since the epoch:
date_time_secs = time.mktime(datetimeobj.timetuple())
or for the whole thing in miliseconds
date_time_milis = time.mktime(datetimeobj.timetuple()) * 1000 + datetimeobj.microsecond / 1000
or similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With