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


Groups > comp.lang.python > #76249

Re: how to change the time string into number?

Date 2014-08-13 21:16 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: how to change the time string into number?
References <53EC14EC.2090503@gmail.com> <20140813210111.197005cd@bigbox.christie.dr>
Newsgroups comp.lang.python
Message-ID <mailman.12958.1407982655.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-08-13 21:01, Tim Chase wrote:
> On 2014-08-14 09:46, luofeiyu wrote:
> > s="Aug"
> > 
> > how can i change it into 8 with some python time module?
> 
>  >>> import time
>  >>> s = "Aug"
>  >>> time.strptime(s, "%b").tm_mon
>  8
> 
> works for me.

Or, if you want a more convoluted way:

 >>> import calendar as c
 >>> [i for i, m in enumerate(c.month_abbr) if m == "Aug"].pop()
 8

-tkc


Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: how to change the time string into number? Tim Chase <python.list@tim.thechases.com> - 2014-08-13 21:16 -0500
  Re: how to change the time string into number? YBM <ybmess@nooos.fr.invalid> - 2014-08-14 04:51 +0200
    Re: how to change the time string into number? Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-13 21:07 -0600
    Re: how to change the time string into number? Roy Smith <roy@panix.com> - 2014-08-13 23:14 -0400
  Re: how to change the time string into number? Marko Rauhamaa <marko@pacujo.net> - 2014-08-14 08:19 +0300

csiph-web