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?

Date 2014-08-14 14:52 +0800
From luofeiyu <elearn2014@gmail.com>
Subject Re: how to change the time string into number?
References <53EC14EC.2090503@gmail.com> <85mwb77rs8.fsf@benfinney.id.au>
Newsgroups comp.lang.python
Message-ID <mailman.12972.1407999152.18130.python-list@python.org> (permalink)

Show all headers | 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