Converting date to milliseconds since 1-1-70

N

NateM

How do I convert any given date into a milliseconds value that
represents the number of milliseconds that have passed since January 1,
1970 00:00:00.000 GMT?
Is there an easy way to do this like Date in java?
Thanks,
Nate
 
G

gry

NateM said:
How do I convert any given date into a milliseconds value that
represents the number of milliseconds that have passed since January 1,
1970 00:00:00.000 GMT?
Is there an easy way to do this like Date in java?
Thanks,
Nate

The main module for dates and times is "datetime"; so
2006-01-24 15:13:35.012755

To get at the "epoch" value, i.e. seconds since 1/1/1970, use the
"time" module:
1138133615.0

Now just add in the microseconds:1138133615.01

Use the "%" formatting operator to display more resolution:1138133615.012755

Note that the floating point division above is not exact and could
possibly
mangle the last digits.

Another way to this data is the datetime.strftime member:
'1138133615.012755'

This gets you a string, not a number object. Converting the string to
a number again risks inaccuracy in the last digits:1138133615.0127549
 
N

NateM

Thank you! If I am reading in dates as strings from a text file, like
"5/11/1998", how do I convert that to a format I can pass into mktime?
Thanks again.
 
X

Xavier Morel

NateM said:
Thank you! If I am reading in dates as strings from a text file, like
"5/11/1998", how do I convert that to a format I can pass into mktime?
Thanks again.
Check time.strptime()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top