P
Peter Kleiweg
Is there a safe and clean way to parse a date/time string into
seconds since epoch?
I have a string with date and time in GMT. I can get the correct
value using this:
#!/usr/bin/env python
import os
os.environ['TZ'] = 'UTC'
import time
s = 'Wed, 06 Jul 2005 16:49:38 GMT'
seconds = time.mktime(time.strptime(s, '%a, %d %b %Y %H:%M:%S %Z'))
However, I also need conversions to localtime. Setting TZ to UTC
before importing the time module won't let me do this. Changing
TZ after importing time has no effect.
seconds since epoch?
I have a string with date and time in GMT. I can get the correct
value using this:
#!/usr/bin/env python
import os
os.environ['TZ'] = 'UTC'
import time
s = 'Wed, 06 Jul 2005 16:49:38 GMT'
seconds = time.mktime(time.strptime(s, '%a, %d %b %Y %H:%M:%S %Z'))
However, I also need conversions to localtime. Setting TZ to UTC
before importing the time module won't let me do this. Changing
TZ after importing time has no effect.