timedelta problem

Chris Angelico rosuav at gmail.com
Thu Aug 14 23:59:42 EDT 2014


On Fri, Aug 15, 2014 at 1:51 PM, Denis McMahon <denismfmcmahon at gmail.com> wrote:
> On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote:
>
>> import datetime
>> t1='Sat, 09 Aug 2014 07:36:46 -0700'
>> t2='Sat, 09 Aug 2014 07:36:46 +0700'
>> datetime.datetime.strptime(t1,"%a, %d %b %Y %H:%M:%S %z")
>
> Are you sure? When I try this I get:
>
> ValueError: 'z' is a bad directive in format '%a, %d %b %Y %H:%M:%S %z'
>
>> datetime.datetime(2014, 8, 9, 7, 36, 46,
>> tzinfo=datetime.timezone(datetime.timedelta(-1, 61200)))
>
> And this:
>
> AttributeError: 'module' object has no attribute 'timezone'

Both fail as you describe in 2.7, but in 3.4/3.5ish (my 'python3' is a
bit of a mess, but it's something between those two I think), both
work as per the OP's description. You both need to be clearer about
version numbers, I think :) The OP did have a link to docs with 3.4 in
the name, although that isn't proof necessarily.

ChrisA



More information about the Python-list mailing list