Python Library Reference
Previous: Up: 5.1.8 Examples Next:

5.1.8.1 Creating Datetime Objects from Formatted Strings

The datetime class does not directly support parsing formatted time strings. You can use time.strptime to do the parsing and create a datetime object from the tuple it returns:

>>> s = "2005-12-06T12:13:14"
>>> from datetime import datetime
>>> from time import strptime
>>> datetime(*strptime(s, "%Y-%m-%dT%H:%M:%S")[0:6])
datetime.datetime(2005, 12, 6, 12, 13, 14)

Python Library Reference
Previous: Up: 5.1.8 Examples Next:

Release 2.5, documentation updated on 19th September, 2006.
See About this document... for information on suggesting changes.

AltStyle によって変換されたページ (->オリジナル) /