There is no wildcard operator. The list of format directives supported by strptime
is in the docs.
What you're looking for is the %z
format directive, which supports a representation of the timezone of the form +HHMM
or -HHMM
. While it has been supported by datetime.strftime
for some time, it is only supported in strptime
starting in Python 3.2.
On Python 2, the best way to handle this is probably to use datetime.datetime.strptime
, manually handle the negative offset, and get a datetime.timedelta
:
import datetime
tz = "+10:00"
def tz_to_timedelta(tz):
min = datetime.datetime.strptime('', '')
try:
return -(datetime.datetime.strptime(tz,"-%H:%M") - min)
except ValueError:
return datetime.datetime.strptime(tz,"+%H:%M") - min
print tz_to_timedelta(tz)
In Python 3.2, remove the :
and use %z
:
import time
tz = "+10:00"
tz_toconvert = tz[:3] + tz[4:]
tz_struct_time = time.strptime(tz_toconvert, "%z")