how to change the time string into number?
Akira Li
4kir4.1i at gmail.com
Wed Aug 20 10:01:24 EDT 2014
luofeiyu <elearn2014 at 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
More information about the Python-list
mailing list