1

Possible Duplicate:
Python strptime() and timezones?

I have string like [22/Aug/2012:13:08:27 +0400] and how I can convert it in time tuple with strptime function?

time.strptime(t, '[%d/%b/%Y:%H:%M:%S +0400]')

works but obviously I need format time offset too.

And when I try format +0400 with %Z, I have:

ValueError: time data '[22/Aug/2012:13:08:27 +0400]' does not match format '[%d/%b/%Y:%H:%M:%S %Z]'

and when I try %z

ValueError: 'z' is a bad directive in format '[%d/%b/%Y:%H:%M:%S %z]'
Community
  • 1
  • 1
Denis
  • 7,127
  • 8
  • 37
  • 58

1 Answers1

2

Indeed, time.strptime() does not support the %z formatter.

The dateutil module includes a parser that does support parsing timezones.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343