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


Groups > comp.lang.python > #76245 > unrolled thread

Re: how to change the time string into number?

Started byBen Finney <ben+python@benfinney.id.au>
First post2014-08-14 12:01 +1000
Last post2014-08-14 12:01 +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.


Contents

  Re: how to change the time string into number? Ben Finney <ben+python@benfinney.id.au> - 2014-08-14 12:01 +1000

#76245 — Re: how to change the time string into number?

FromBen Finney <ben+python@benfinney.id.au>
Date2014-08-14 12:01 +1000
SubjectRe: how to change the time string into number?
Message-ID<mailman.12954.1407981739.18130.python-list@python.org>
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

-- 
 \        “I knew it was a shocking thing to say, but … no-one has the |
  `\        right to spend their life without being offended.” —Philip |
_o__)                                              Pullman, 2010-03-28 |
Ben Finney

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web