Returning millisecond datetime representation in python

Using Python, I save the date and time as datetime.datetime in GAE. Is there a way to get the date value in milliseconds as opposed to a fully formatted version of the string?

Based on the docs for datetime.datetime, I don't see any built-in methods in the date time class that does this. http://docs.python.org/release/2.5.2/lib/datetime-datetime.html

The original date value is saved as follows:

date_time_float = 1015182600 #some date as timestamp date_time_object = datetime.fromtimestamp(date_time_float); 

When I retrieve data from the store, it is of type:

 type(exported_date_time) # type: datetime.datetime 

There's strftime to convert to a string representation, but what I'm looking for is to convert 'exported_date_time' to milliseconds.

+8
python google-app-engine
source share
1 answer

To get seconds from an era:

 date_time_secs = time.mktime(datetimeobj.timetuple()) 

or for all this in milliseconds

 date_time_milis = time.mktime(datetimeobj.timetuple()) * 1000 + datetimeobj.microsecond / 1000 

or similar.

+14
source share

All Articles