Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76347

Re: timedelta problem

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: timedelta problem
Date 2014-08-15 13:34 +1000
References <53ED6F6F.2030004@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.13022.1408073706.18130.python-list@python.org> (permalink)

Show all headers | View raw


luofeiyu <elearn2014@gmail.com> writes:

> 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")
> datetime.datetime(2014, 8, 9, 7, 36, 46,
> tzinfo=datetime.timezone(datetime.timed
> elta(-1, 61200)))
> >>> datetime.datetime.strptime(t2,"%a, %d %b %Y %H:%M:%S %z")
> datetime.datetime(2014, 8, 9, 7, 36, 46,
> tzinfo=datetime.timezone(datetime.timed
> elta(0, 25200)))

(Your examples will be easier to read – and you will help those who are
helping you – if you conform to PEP 8 in the code, and don't break up
the output when you copy it here.)

> problem :
>
> t1 is GMT time   2014  00:36:46
> t2 is GMT time   2014  14:36:46

Not true; t1 and t2 are not in the “GMT” zone, they are in UTC-0700 and
UTC+0700 respectively. Their value includes that.

The instants they *represent* may be equal to the times-plus-timezone
you've listed here, but their value is different. The value includes the
timezone information, so they're different from what you show.

> datetime.datetime.strptime  do not give me the right answer.

What do you think the right answer would be in each case? Why?

-- 
 \     “The aim of science is not to open the door to infinite wisdom, |
  `\        but to set some limit on infinite error.” —Bertolt Brecht, |
_o__)                                        _Leben des Galilei_, 1938 |
Ben Finney

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: timedelta  problem Ben Finney <ben+python@benfinney.id.au> - 2014-08-15 13:34 +1000

csiph-web