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


Groups > comp.lang.python > #76270

Re: how to change the time string into number?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <elearn2014@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'represents': 0.05; 'indicating': 0.07; 'here?': 0.09; 'subject:into': 0.09; 'subject:number': 0.09; 'subject:string': 0.09; 'python': 0.11; '8bit%:32': 0.16; 'directive': 0.16; 'finney': 0.16; 'module?': 0.16; 'url:time': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'email addr:gmail.com&gt;': 0.22; 'manual': 0.22; 'header:User-Agent:1': 0.23; '&gt;&gt;&gt;': 0.24; 'parse': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'characters': 0.30; 'decimal': 0.31; 'piece': 0.31; 'writes:': 0.31; 'text': 0.33; 'url:python': 0.33; 'subject:time': 0.33; 'subject:the': 0.34; 'received:google.com': 0.35; 'object,': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'positive': 0.37; 'received:10': 0.37; 'message-id:@gmail.com': 0.38; 'ben': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'negative': 0.60; 'skip:t 30': 0.61; 'url:3': 0.61; 'name': 0.63; 'different': 0.65; 'skip:\xe2 10': 0.65; '8bit%:31': 0.68; 'url:4': 0.69; 'hour': 0.70; ',the': 0.84
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:subject:references :in-reply-to:content-type; bh=3IqOJZ1WtwYbBbiCJWKTfB0JynkkJBXCRkRP6vxTHhs=; b=RyEJWZwuCTZJ2sDGYp/bhHEYZXgrAHXuJq1u4IIMkUOd+05eno8OQOzsfl+AU4gS0F dnto3+HZLv+2UBXt1189Q+a835XCPIK/WH8M39BES3w2WIa9E4Lsx9sXhKUVMuBuygNi jj4L3qwn2xm3r3ZmXb+yKtQSB3b/T5ME+hCxyxQI17rJ9V7HlBABNwmJK3ihk8i8RFMa kd6sp2yFXCz2K9W6Fv01UYlGO1qBieaNoOEhMN5gkjnjGRGGGplK8PLHpuZ3372Nr8Ll e/YtGKDCPfyi6txuT7OIskOu/dhBk/vfvC9tjOtgqSS4AFS3v6viBgB8fZeT44RdY1pj zKKA==
X-Received by 10.66.182.69 with SMTP id ec5mr2327772pac.125.1407999149500; Wed, 13 Aug 2014 23:52:29 -0700 (PDT)
Date Thu, 14 Aug 2014 14:52:17 +0800
From luofeiyu <elearn2014@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0
MIME-Version 1.0
To python-list@python.org
Subject Re: how to change the time string into number?
References <53EC14EC.2090503@gmail.com> <85mwb77rs8.fsf@benfinney.id.au>
In-Reply-To <85mwb77rs8.fsf@benfinney.id.au>
Content-Type multipart/alternative; boundary="------------070206090805030407010703"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12972.1407999152.18130.python-list@python.org> (permalink)
Lines 140
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407999152 news.xs4all.nl 2862 [2001:888:2000:d::a6]:52425
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76270

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

in the manual  https://docs.python.org/3.4/library/time.html

%z 	Time zone offset indicating a positive or negative time difference 
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?

 >>> 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?

On 8/14/2014 10:01 AM, Ben Finney wrote:
> luofeiyu <elearn2014@gmail.com> writes:
>
>> s="Aug"
>>
>> how can i change it into 8 with some python time module?
> What is your purpose here? If you want to parse a text value into a
> structured time object, don't do it piece by piece. Use the
> ‘time.strptime’ function.
>
>      >>> import time
>      >>> input_time_text = "14 Aug 2014"
>      >>> input_time = time.strptime(input_text, "%d %b %Y")
>      >>> input_time.tm_mon
>      8
>

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: how to change the time string into number? luofeiyu <elearn2014@gmail.com> - 2014-08-14 14:52 +0800
  Re: how to change the time string into number? Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-15 14:19 +0000

csiph-web