Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76270 > unrolled thread
| Started by | luofeiyu <elearn2014@gmail.com> |
|---|---|
| First post | 2014-08-14 14:52 +0800 |
| Last post | 2014-08-15 14:19 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | luofeiyu <elearn2014@gmail.com> |
|---|---|
| Date | 2014-08-14 14:52 +0800 |
| Subject | Re: how to change the time string into number? |
| Message-ID | <mailman.12972.1407999152.18130.python-list@python.org> |
[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 >
[toc] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-08-15 14:19 +0000 |
| Message-ID | <lsl4u8$8u4$3@dont-email.me> |
| In reply to | #76270 |
On Thu, 14 Aug 2014 14:52:17 +0800, luofeiyu wrote: > 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? Please learn to use usenet properly. Comments go below the text they refer to. What version of python are you using? I know what version of the documentation you are looking at, but as I explained inj an earlier post, the implementation varies between different python versions, and for example python 2.7 strptime seems to completely ignore the %z in the format string, so again, what version of python are you using? To check your python version: $ python >>> import sys >>> sys.version will output something like: '2.7.3 (default, Feb 27 2014, 19:58:35) \n[GCC 4.6.3]' for Python 2.7 or: '3.2.3 (default, Feb 27 2014, 21:31:18) \n[GCC 4.6.3]' for Python 3.2. Again, I stress, we need to know what version of python you are using to help you! Did you run the code I posted? Did you get the same output as me? If you didn't, what was different. If you did get the same output, what do you think is wrong with it? -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web