Python strptime() and timezones?

后端 未结 5 1204
栀梦
栀梦 2020-11-22 11:58

I have a CSV dumpfile from a Blackberry IPD backup, created using IPDDump. The date/time strings in here look something like this (where EST is an Australian ti

5条回答
  •  旧巷少年郎
    2020-11-22 12:41

    Your time string is similar to the time format in rfc 2822 (date format in email, http headers). You could parse it using only stdlib:

    >>> from email.utils import parsedate_tz
    >>> parsedate_tz('Tue Jun 22 07:46:22 EST 2010')
    (2010, 6, 22, 7, 46, 22, 0, 1, -1, -18000)
    

    See solutions that yield timezone-aware datetime objects for various Python versions: parsing date with timezone from an email.

    In this format, EST is semantically equivalent to -0500. Though, in general, a timezone abbreviation is not enough, to identify a timezone uniquely.

提交回复
热议问题