Unix Timestamps in Python
I use Unix timestamps for a great many things and just spent some time looking this up:
from time import time mySeconds = time()
It’s simple enough, but remember: this function returns a float! It generally yields about two digits of precision. For straight Unix seconds use floor (or just the int cast), as rounding the number may put you one second ahead.
from time import time myUnixSeconds = int(time())
You may also want to have a look at the official Python documentation for the Time module.
This entry was posted
on Monday, March 24th, 2008 at 1:45 pm and is filed under Code Hints.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Leave a Reply
You must be logged in to post a comment.










