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


Groups > comp.lang.python > #76347 > unrolled thread

Re: timedelta problem

Started byBen Finney <ben+python@benfinney.id.au>
First post2014-08-15 13:34 +1000
Last post2014-08-15 13:34 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#76347 — Re: timedelta problem

FromBen Finney <ben+python@benfinney.id.au>
Date2014-08-15 13:34 +1000
SubjectRe: timedelta problem
Message-ID<mailman.13022.1408073706.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web