how to change the time string into number?

luofeiyu elearn2014 at gmail.com
Thu Aug 14 02:52:17 EDT 2014


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140814/7274f167/attachment.html>


More information about the Python-list mailing list