Parsing Datetime in Python with timezone -


how parse date , time time zone?

date_time=datetime.strptime("2017-06-04t01:00:00+04:00", '%y-%m-%dt%h:%m:%s%z') 

i getting error

valueerror: time data '2017-06-04t01:00:00+04:00' not match format '%y-%m-%dt%h:%m:%s %z'

while remove "%z" error

valueerror: unconverted data remains: +04:00 

i think error in formatting time zone. please on this.

it doesn't appear me strptime has directive coping time zone information in format. part of string in indicating time zone needs without colon.

>>> datetime import datetime >>> datetime.strptime("2017-06-04t01:00:00+0400", '%y-%m-%dt%h:%m:%s%z') datetime.datetime(2017, 6, 4, 1, 0, tzinfo=datetime.timezone(datetime.timedelta(0, 14400))) 

you can arrange preprocess date regex of course:

>>> re.sub(r'(?<=[+=][0-9]{2}):', '', "2017-06-04t01:00:00+04:00") '2017-06-04t01:00:00+0400' 

if can allow use of library not part of standard distribution arrow suitable since it's timestamps.

>>> import arrow >>> arrow.get("2017-06-04t01:00:00+04:00") <arrow [2017-06-04t01:00:00+04:00]> 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

angular - Copying node modules to wwwroot AspNetCore -