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


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

Re: how to change the time string into number?

Started byAkira Li <4kir4.1i@gmail.com>
First post2014-08-20 18:01 +0400
Last post2014-08-20 18:01 +0400
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? Akira Li <4kir4.1i@gmail.com> - 2014-08-20 18:01 +0400

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

FromAkira Li <4kir4.1i@gmail.com>
Date2014-08-20 18:01 +0400
SubjectRe: how to change the time string into number?
Message-ID<mailman.13208.1408543323.18130.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web