I am trying to convert time into epoch time. I am getting the error of:
ValueError: time data '11/Jan/2014:08:33:48 -0800' does not match format '%d/%b/%Y:%H:%M:%S %Z'
import time
def epoch_time(epoch):
d = "11/Jan/2014:08:33:48 -0800"
p='%d/%b/%Y:%H:%M:%S %Z'
epoch = int(time.mktime(time.strptime(d,p)))
print epoch
What is wrong with my above code?
My second question is where is TZ defined in os.environ[TZ]='UTC'? I found this in another post.
Update: My data comes in this format: 11/Jan/2014:08:33:48 -0800 - it comes with time zone info of -8000. I can not modify the data but need to modify the code. Using Python 2.7.6
>>> from dateutil import parser
>>> dd = parser.parse('11/Jan/2014:08:33:48 -0800')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/dateutil/parser.py", line 1008, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/dateutil/parser.py", line 395, in parse
raise ValueError("Unknown string format")
ValueError: Unknown string format
>>>