Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'represents': 0.05; 'root': 0.05; 'string.': 0.05; 'indicating': 0.07; 'interpreter.': 0.07; 'parser': 0.07; 'sys': 0.07; 'string': 0.09; 'attributes': 0.09; 'difference,': 0.09; 'extracted': 0.09; 'facts': 0.09; 'output,': 0.09; 'subject:into': 0.09; 'subject:number': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '(about': 0.16; 'charles': 0.16; 'directive': 0.16; 'reason.': 0.16; 'simpson': 0.16; 'storing': 0.16; 'supplied': 0.16; 'url:time': 0.16; 'wrote:': 0.18; 'library': 0.18; 'bit': 0.19; 'else,': 0.19; '>>>': 0.22; 'platforms': 0.22; 'import': 0.22; 'aug': 0.22; 'manual': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'text.': 0.24; 'cheers,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'characters': 0.30; 'skip:( 20': 0.30; 'decimal': 0.31; 'struct': 0.31; 'allows': 0.31; 'text': 0.33; 'says': 0.33; 'url:python': 0.33; 'running': 0.33; 'alone': 0.33; 'subject:time': 0.33; 'subject:the': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'example,': 0.37; 'positive': 0.37; 'received:10': 0.37; 'message-id:@gmail.com': 0.38; 'same.': 0.38; 'url:library': 0.38; 'pm,': 0.38; 'little': 0.38; 'does': 0.39; 'embedded': 0.39; 'supporting': 0.39; 'changed': 0.39; 'middle': 0.60; 'negative': 0.60; 'tell': 0.60; 'skip:t 30': 0.61; 'url:3': 0.61; 'john': 0.61; "you're": 0.61; 'back': 0.62; 'times': 0.62; 'information': 0.63; 'name': 0.63; 'more': 0.64; 'different': 0.65; 'teach': 0.65; 'mar': 0.68; 'url:4': 0.69; '8bit%:100': 0.72; 'therefore': 0.72; 'life.': 0.83; ',the': 0.84; '2014,': 0.84; '3.4': 0.84; 'boys': 0.84; 'imagine,': 0.84; '\xe2\x94\x82': 0.84; 'girls': 0.91; 'plant': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=ZHQAZwb1y5kuqaBVWMRkl259qrtnb6xSJpiLvU17xgY=; b=ZUkcwXgKCtP8BiyirJdvDSb1dpzrrEieFVvFV3szv1hPa1ttviHtAqvofMSGdm5fhN y2nkOjTNVsoU17dpayaMdRiSIk95+vvTj/LVXFDgjHEYPlk9NU3Kupv436hwv+dH3NyO Y8i3EDVd2kXzbI98ZbVkx8IwjHdtv98DHV38BUOUp8++BOBNLT8bh1TVRiXSsrJj5paR 7Z5zHGycOfwRSemrCvgbu85wKLdFqXckSwUpJ0kFU8DBIAyolCJFpYB3zBPM1ccniplu QOajv1td0wgsqCdJ0kwRNS5TJBzRTN/udlHR3DfkCPYE3OoUC1im8r6Usr6n4cv01ECZ +RXQ== X-Received: by 10.70.91.208 with SMTP id cg16mr8360573pdb.91.1408001443321; Thu, 14 Aug 2014 00:30:43 -0700 (PDT) Date: Thu, 14 Aug 2014 15:30:33 +0800 From: luofeiyu User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Cameron Simpson Subject: Re: how to change the time string into number? References: <53EC5CA1.5090002@gmail.com> <20140814072549.GA69472@cskk.homeip.net> In-Reply-To: <20140814072549.GA69472@cskk.homeip.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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: 98 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408001452 news.xs4all.nl 2829 [2001:888:2000:d::a6]:44107 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76275 >>> import sys >>> sys.version '3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)]' >>> import time >>> time.tzname ('China Standard Time', 'China Daylight Time') On 8/14/2014 3:25 PM, Cameron Simpson wrote: > On 14Aug2014 14:52, luofeiyu wrote: >> in the manual https://docs.python.org/3.4/library/time.html >> >> ┌──┬──────────────────────────────────────────────────────────────────────┬─┐ >> >> │ │Time zone offset indicating a positive or negative time >> difference │ │ >> │%z│from UTC/GMT of the form +HHMM or -HHMM, where H represents >> decimal │ │ >> │ │hour digits and M represents decimal minute digits [-23:59, >> +23:59]. │ │ >> ├──┼──────────────────────────────────────────────────────────────────────┼─┤ >> >> │%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) >> >>>>> 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? > > What you get back a struct_time, which is little more than the numeric > values extracted from a time string. And as far as the text you have > supplied in your example, those values are the same. > > Regarding the difference, string in t2 has a time zone offset. > > My Python 3.4 doco says (about struct_time): > > Changed in version 3.3: tm_gmtoff and tm_zone attributes are > available on platforms with C library supporting the corresponding > fields in struct tm. > > Judging by your output, your C library does not support the tm_gmtoff > and tm_zone fields in its C library "struct tm". > > Please: > > tell us what specific version of Python you are using > > tell us what OS you're running on > > Then look up the localtime() or gmtime() functions for you C library > and see what that documentation says about "struct tm", which is what > they and the C library strptime() return. > >>>>> t3='Sat, 09 Aug 2014 07:36:46 +0400' >>>>> time.strptime(t3,"%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) >> >> The Directive %z has no any effect here,what is the matter? > > The directive allows the strptime parser to keep recognising text. > Imagine, for example, that the timezone were embedded in the middle of > the string for some reason. > > It looks like you platform does not support storing the time zone > information in the C library "struct tm", and therefore it does not > get exposed to the Python interpreter. > > Cheers, > Cameron Simpson > > What I want is Facts. Teach these boys and girls nothing but Facts. > Facts > alone are wanted in life. Plant nothing else, and root out everything > else. > - Charles Dickens John Huffam 1812-1870 Hard Times [1854]