Python Equivalent??
scummer
scummer at 3squares.com
Thu Mar 11 10:15:16 EST 2004
Jeff Epler <jepler at unpythonic.net> wrote in message news:<mailman.202.1078889095.19534.python-list at python.org>...
> Here's the final function:
> def convertDateTime(d, pattern="%Y-%m-%d %H:%M:%S"):
> tup = time.strptime(d, pattern)
> seconds = calendar.timegm(tup)
> assert time.gmtime(seconds)[:6] == tup[:6]
> return seconds
>
> Or, for the terminally terse:
> def convertDateTime(d, p):
> return calendar.timegm(time.strptime(d, p))
>
> Jeff
Thanks a lot Jeff, this is sweet. I came up with the following just
after posting:
def convertDateTime(d, p):
os.environ['TZ'] = "UTC"
time.tzset()
dollop = time.mktime(time.strptime(d, p))
return int(dollop)
But I think yours is superior as I have not quite figured out how to
get the timezone back to the local one again.
Thanks again,
Mark
More information about the Python-list
mailing list