I have a string in this format: Mon Feb 27 2012 13:15:00 GMT+0330 (Iraq Standard Time) ,I’m going to convert it to this format : 2012-02-27T13:15:00.000 , I’ve done this:
startTime=`Mon Feb 27 2012 13:15:00 GMT+0330 (Iraq Standard Time)`
strp_time = time.strptime(startTime, '%a %b %d %Y %H:%M:%S %Z')
start = time.strftime('%Y-%m-%dT%H:%M:%S',strp_time)
But it caused this error:
unconverted data remains: +0330 (Iraq Standard Time)
So,I tryed this to remove (Iraq Standard Time) :
start=re.sub(r' \(.+?\)$', '', startTime)
strp_time = time.strptime(start, '%a %b %d %Y %H:%M:%S %Z')
start = time.strftime('%Y-%m-%dT%H:%M:%S',strp_time)
But,I’m getting this error:
unconverted data remains: +0330
If you change your regex to:
It will work as you can also strip out the time zone difference information (+ or -), this should be ok for you as you are discarding the %Z data anyhow.
You should possiblly be able to use %z to get the +0330 time difference, but it doesn’t work with my Python version, possibly due to a bug. Which seems to be resolved for Python 3.2 see http://bugs.python.org/issue6641