Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.069 X-Spam-Evidence: '*H*': 0.86; '*S*': 0.00; 'argument': 0.05; 'linux,': 0.07; 'utf-8': 0.07; 'historic': 0.09; 'whichever': 0.09; 'windows,': 0.09; '\xe2\x80\x94': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '2.7': 0.14; 'windows': 0.15; '###': 0.16; 'happily': 0.16; 'imports': 0.16; 'i\xe2\x80\x99m': 0.16; 'objects*.': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'example': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'delta': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'skip:p 30': 0.29; 'am,': 0.29; 'database,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'seemingly': 0.31; 'url:python': 0.33; 'running': 0.33; 'subject:time': 0.33; 'sense': 0.34; 'something': 0.35; 'objects': 0.35; 'usual': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'object,': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'thank': 0.38; 'anything': 0.39; '12,': 0.39; 'url:mail': 0.40; 'how': 0.40; 'future': 0.60; 'from:charset:utf-8': 0.61; 'you.': 0.62; 'taking': 0.65; 'account': 0.65; 'skip:\xe2 10': 0.65; 'between': 0.67; 'to:addr:aol.com': 0.68; 'url:v': 0.71; 'url:youtube': 0.71; '8bit%:43': 0.74; 'url:watch': 0.77; 'savings': 0.81; 'it\xe2\x80\x99s': 0.84; 'ships': 0.84; 'subject:savings': 0.84; 'suits': 0.84; 'tricky': 0.84; 'do:': 0.91; 'why?': 0.91; 'washington': 0.93; 'url:tk': 0.95; 'yourself,': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=AYWGKxpm6AjBlhAqqzaOAzv24rWKohcl9BNNpO6oePw=; b=pBDyT1cjWnLWjdM5ZKNe45v6vQ09Jw1XrDbuADgjmzD8C0FwG60Cas21dxgM8WjPyi Xy9vMsAQerwS4/OUwht6fAQtsleDyTwV5WqNmdaqE9Toe+qzzOn55zckP4BpGWKuPnu1 Bn5K3sw0MI2n3SkQ8tg9PTqv0m8XpYevPTNqRHm9qNqAs6m8+XKCElwcRdRpAc8alfuD IzFq9TVlKlp+VLCUqTjAooh/JqgvOJbif+hwzCwZDrB3+TMzedJwKnPK6r9Y4WudlwIT DHpDzrJjlPqIP+2hQZzYlRjzWj/qb6uszGqjR1v9moU3PwZFbg/ohM+NDTzeyCVcylm3 ISEA== MIME-Version: 1.0 X-Received: by 10.50.66.143 with SMTP id f15mr15626756igt.18.1396532810245; Thu, 03 Apr 2014 06:46:50 -0700 (PDT) In-Reply-To: References: Date: Thu, 3 Apr 2014 15:46:50 +0200 Subject: Re: Calculating time differences given daylight savings time From: =?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?= To: Washington Ratso Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396532818 news.xs4all.nl 2839 [2001:888:2000:d::a6]:38921 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69581 On Thu, Apr 3, 2014 at 3:45 AM, Washington Ratso wrote= : > I am running Python 2.7 and would like to be able to calculate to the sec= ond the time difference between now and some future date/time in the same t= imezone while taking into account daylight savings time. I do not have pyt= z. Any ideas how to do it? > > If it requires having pytz, how would I do it with pytz? > > Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list It requires having pytz, or dateutil, in order to get timezone objects*. You can also create those objects yourself, but that=E2=80=99s tricky =E2=80=94 and you SHOULD NOT do time zones on your own and just use something else. Why? See [0]. Example with pytz: # Necessary imports import pytz from datetime import datetime # the timezone in this example is Europe/Warsaw =E2=80=94 use your favorite= one tz =3D pytz.timezone('Europe/Warsaw') now =3D datetime.now(tz) # Note I=E2=80=99m not using the tzinfo=3D argument of datetime(), it=E2=80= =99s flaky and seemingly uses a historic WMT (+01:24) timezone that is dead since 1915. future =3D tz.localize(datetime(2014, 12, 24)) # And now you can happily do: delta =3D future - now # and you will get the usual timedelta object, which you can use the usual = way. ### * pytz ships the Olson tz database, while dateutil maps uses your system=E2=80=99s copy of the tz database (if you are on Linux, OS X or anything else that is not Windows, really) or maps to the Windows registry. Use whichever suits you. [0]: http://www.youtube.com/watch?v=3D-5wpm-gesOY --=20 Chris =E2=80=9CKwpolska=E2=80=9D Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense