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


Groups > comp.lang.python > #13116

Re: convert time

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: convert time
References <mailman.970.1315716418.27778.python-list@python.org> <4e6c4088$0$29965$c3e8da3$5496439d@news.astraweb.com>
Date 2011-09-11 15:30 +1000
Message-ID <8762kzmys5.fsf@benfinney.id.au> (permalink)
Organization Unlimited download news at news.astraweb.com

Show all headers | View raw


Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:

> But seriously... 2011-12 is not a proper date

It's valid by ISO 8601. The standard allows any number of parts to be
dropped, from least to most significant, in order to have a value with
deliberately reduced precision.

   <URL:https://secure.wikimedia.org/wikipedia/en/wiki/ISO_8601#General_principles>

> Otherwise see the time and datetime modules:

    >>> import datetime
    >>> text = "2011-12"
    >>> datetime.datetime.strptime(text, "%Y-%m")
    datetime.datetime(2011, 12, 1, 0, 0)

-- 
 \            “It's not what you pay a man, but what he costs you that |
  `\                                             counts.” —Will Rogers |
_o__)                                                                  |
Ben Finney

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


Thread

convert  time "守株待兔" <1248283536@qq.com> - 2011-09-11 12:46 +0800
  Re: convert  time Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-11 15:00 +1000
    Re: convert  time Ben Finney <ben+python@benfinney.id.au> - 2011-09-11 15:30 +1000
    Re: convert time nn <pruebauno@latinmail.com> - 2011-09-12 10:42 -0700

csiph-web