Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'url:pypi': 0.03; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spaces': 0.09; 'subject:into': 0.09; 'subject:number': 0.09; 'subject:string': 0.09; 'python': 0.11; '8bit%:32': 0.16; 'arbitrarily,': 0.16; 'directive': 0.16; 'finney': 0.16; 'quoted': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recognizing': 0.16; 'top-post': 0.16; 'url:time': 0.16; 'utc': 0.16; 'library': 0.18; 'examples': 0.20; '>>>': 0.22; '(in': 0.22; 'aug': 0.22; 'manual': 0.22; 'install': 0.23; 'header:User- Agent:1': 0.23; '(see': 0.26; 'supported': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'characters': 0.30; 'database,': 0.30; 'code': 0.31; 'easier': 0.31; 'url:wiki': 0.31; 'material.': 0.31; 'operators': 0.31; 'url:wikipedia': 0.31; 'writes:': 0.31; 'url:python': 0.33; 'style': 0.33; 'subject:time': 0.33; 'subject:the': 0.34; 'except': 0.35; 'date.': 0.36; 'described': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'example,': 0.37; 'ben': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'remove': 0.60; 'read': 0.60; 'skip:t 30': 0.61; 'lost': 0.61; 'url:3': 0.61; "you'll": 0.62; 'name': 0.63; 'different': 0.65; 'skip:\xe2 10': 0.65; 'latest': 0.67; 'response.': 0.68; 'subject': 0.69; 'url:4': 0.69; 'savings': 0.81; ',the': 0.84; 'irrelevant': 0.84; 'received:125': 0.84; 'warning.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: how to change the time string into number? Date: Thu, 14 Aug 2014 17:22:09 +1000 References: <53EC14EC.2090503@gmail.com> <85mwb77rs8.fsf@benfinney.id.au> <53EC5CA1.5090002@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:jSynWwjyf3IXIsvViKnmPQkW+jA= 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: 1408000945 news.xs4all.nl 2858 [2001:888:2000:d::a6]:35402 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76273 Please don't top-post your response. Instead, interleave your response and remove irrelevant quoted material. Use the Interleaved style . luofeiyu writes: > in the manual https://docs.python.org/3.4/library/time.html > > %z Time zone offset […] > %Z Time zone name (no characters if no time zone exists). > t1='Sat, 09 Aug 2014 07:36:46 ' > time.strptime(t1,"%a, %d %b %Y %H:%M:%S ") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, > tm_min=36, tm_sec > =46, tm_wday=5, tm_yday=221, tm_isdst=-1) Your code examples will be easier to read if you follow PEP 8 (in this example, spaces around the operators as described in the style guide). > >>> t2='Sat, 09 Aug 2014 07:36:46 -0700' > >>> time.strptime(t2,"%a, %d %b %Y %H:%M:%S %z") > time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7, > tm_min=36, tm_sec > =46, tm_wday=5, tm_yday=221, tm_isdst=-1) > > t1 and t2 is different time ,the timezone in t2 is -0700 ,why we get > the same result? The timezone in ‘t2’ will only be understood subject to the caveat: Support for the %Z directive is based on the values contained in tzname and whether daylight is true. Because of this, it is platform-specific except for recognizing UTC and GMT which are always known (and are considered to be non-daylight savings timezones). So you'll need to see what your Python implementation supports (see ‘time.tzname’). The support for time zones is always a pain, because they *change* rapidly, arbitrarily, and with very little warning. Because of this, the Python standard library does not attempt to contain a timezone database, since it would almost immediately be out of date. Install the ‘pytz’ package to get the latest released timezone database supported in Python . -- \ “It is better to have loft and lost than to never have loft at | `\ all.” —Groucho Marx | _o__) | Ben Finney