Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.037 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '36,': 0.16; '46,': 0.16; 'skip:d 60': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'later': 0.20; '>>>': 0.22; 'aug': 0.22; 'email addr:gmail.com>': 0.22; '>>>': 0.24; 'subject:problem': 0.24; 'looks': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'message-id:@mail.gmail.com': 0.30; 'skip:t 40': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.35; '14,': 0.36; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'ian': 0.60; 'answer.': 0.68 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=yZnV5+raiJ0lUTFECFUVqnpdxUHDT4kQg+jfzJV+wrM=; b=i0wUjnwkISip4GJz4zB6EnlX+iDVrDb/VinrxW5+iUgcaSSLbfrvWyZl2HfUv0Lh/2 ge3FJi3UAgjoIj10qfq1nOAiNpqEf7ELDFUGtQKWICrspVmGryUHnoxEM7xVtm2gEVhq L+MwCTMsPT0SnNSvtWXs/18pEW9O3BdwUHrGE9NSXRSCN+YHMIckWtNW69TgcISazkfT pFxCK/33wivaUNSrMoVQlQhPDzxfGQPtC8+3avGUgVQS7Jk2fsxjEA2kcniZsnqu0S7i Ym3nV7BGGEVaw1fdtfTHiMRv3rDtlzN5bsgX92khgxIsMOc4pFHZnWjRNBXlxgA2FbTT MhIQ== X-Received: by 10.70.137.98 with SMTP id qh2mr3237860pdb.61.1408074334537; Thu, 14 Aug 2014 20:45:34 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <53ED6F6F.2030004@gmail.com> From: Ian Kelly Date: Thu, 14 Aug 2014 21:44:54 -0600 Subject: Re: timedelta problem To: Python Content-Type: multipart/alternative; boundary=001a1136032c870f350500a2da18 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408074339 news.xs4all.nl 2872 [2001:888:2000:d::a6]:36348 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76349 --001a1136032c870f350500a2da18 Content-Type: text/plain; charset=UTF-8 On Thu, Aug 14, 2014 at 9:37 PM, Ian Kelly wrote: > On Thu, Aug 14, 2014 at 8:24 PM, luofeiyu wrote: > > t1 is GMT time 2014 00:36:46 > > t2 is GMT time 2014 14:36:46 > > You have it backwards. t1 is a later time than t2. > > > datetime.datetime.strptime do not give me the right answer. > > >>> dt1 - dt2 > datetime.timedelta(0, 50400) > >>> _.seconds // 3600 > 14 > > Looks correct to me. Also: >>> dt1.astimezone(datetime.timezone.utc) datetime.datetime(2014, 8, 9, 14, 36, 46, tzinfo=datetime.timezone.utc) >>> dt2.astimezone(datetime.timezone.utc) datetime.datetime(2014, 8, 9, 0, 36, 46, tzinfo=datetime.timezone.utc) --001a1136032c870f350500a2da18 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thu, Aug 14, 2014 at 9:37 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> = On Thu, Aug 14, 2014 at 8:24 PM, luofeiyu <elearn2014@gmail.com> wrote:
> > t1 is GMT time =C2=A0 2014 =C2=A000:36:46
> > t2 is GMT = time =C2=A0 2014 =C2=A014:36:46
>
> You have it backwards. t1 i= s a later time than t2.
>
> > datetime.datetime.strptime =C2= =A0do not give me the right answer.
>
> >>> dt1 - dt2
> datetime.timedelta(0, 50400)> >>> _.seconds // 3600
> 14
>
> Looks corre= ct to me.

Also:

>>&g= t; dt1.astimezone(datetime.timezone.utc)
datetime.datetime(2014, 8, 9, 14, 36, 46, tzinfo=3Ddatetime.timezone.u= tc)
>>> dt2.astimezone(datetime.timezone.utc)
= datetime.datetime(2014, 8, 9, 0, 36, 46, tzinfo=3Ddatetime.timezone.utc)
--001a1136032c870f350500a2da18--