Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76273 > unrolled thread
| Started by | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| First post | 2014-08-14 17:22 +1000 |
| Last post | 2014-08-14 17:22 +1000 |
| Articles | 1 — 1 participant |
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? Ben Finney <ben+python@benfinney.id.au> - 2014-08-14 17:22 +1000
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-08-14 17:22 +1000 |
| Subject | Re: how to change the time string into number? |
| Message-ID | <mailman.12975.1408000945.18130.python-list@python.org> |
Please don't top-post your response. Instead, interleave your response
and remove irrelevant quoted material. Use the Interleaved style
<URL:https://en.wikipedia.org/wiki/Posting_style#Interleaved_style>.
luofeiyu <elearn2014@gmail.com> writes:
> in the manual https://docs.python.org/3.4/library/time.html
>
> %z Time zone offset […]
> %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)
Your code examples will be easier to read if you follow PEP 8 (in this
example, spaces around the operators as described in the style guide).
> >>> 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?
The timezone in ‘t2’ will only be understood subject to the caveat:
Support for the %Z directive is based on the values contained in
tzname and whether daylight is true. Because of this, it is
platform-specific except for recognizing UTC and GMT which are
always known (and are considered to be non-daylight savings
timezones).
<URL:https://docs.python.org/3/library/time.html#time.strptime>
So you'll need to see what your Python implementation supports (see
‘time.tzname’).
The support for time zones is always a pain, because they *change*
rapidly, arbitrarily, and with very little warning. Because of this, the
Python standard library does not attempt to contain a timezone database,
since it would almost immediately be out of date.
Install the ‘pytz’ package to get the latest released timezone database
supported in Python <URL:https://pypi.python.org/pypi/pytz>.
--
\ “It is better to have loft and lost than to never have loft at |
`\ all.” —Groucho Marx |
_o__) |
Ben Finney
Back to top | Article view | comp.lang.python
csiph-web