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


Groups > comp.lang.python > #76664

Re: how to change the time string into number?

From Akira Li <4kir4.1i@gmail.com>
Subject Re: how to change the time string into number?
Date 2014-08-20 18:01 +0400
References <53EC14EC.2090503@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.13208.1408543323.18130.python-list@python.org> (permalink)

Show all headers | View raw


luofeiyu <elearn2014@gmail.com> writes:

> s="Aug"
>
> how can i change it into 8 with some python time module?

  months = (None, # dummy, to start month indices from 1
      "Jan","Feb","Mar","Apr","May","Jun",
      "Jul","Aug","Sep","Oct","Nov","Dec"
  )
  month_number = months.index(month_abbr) # month_abbr == "Aug"

Note:
- time.strptime(month_abbr, "%b").tm_mon may fail in non-English locale
- list(calendar.month_abbr).index(month_abbr) is also locale-specific


--
Akira

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


Thread

Re: how to change the time string into number? Akira Li <4kir4.1i@gmail.com> - 2014-08-20 18:01 +0400

csiph-web