days since epoch

E

eight02645999

hi
how can i get the number of days since epoch using the time module?
or do i have to manually do the arithmetic?
thanks
 
A

Alex Martelli

hi
how can i get the number of days since epoch using the time module?
or do i have to manually do the arithmetic?

Try the datetime module -- better suited to computing days, than the
time module, IMHO.


Alex
 
W

wittempj

As suggested by Alex the datetime module makes this easy:

py> import datetime
py> epoch = datetime.datetime.utcfromtimestamp(0)
py> print epoch
1970-01-01 00:00:00
py> today = datetime.datetime.today()
py> d = today - epoch
py> print d
13196 days, 9:50:44.266200
py> print d.days # timedelta object
13196
 
M

Marius Gedminas

The datetime module is usually more convenient for date/time
arithmetic. However in your particular case, you may find the
time.time() function convenient. It returns the number of seconds
since the epoch. To get the number of days divide the number of
seconds by 86400.
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top