add common usage example

This commit is contained in:
Skip Montanaro 2005-12-06 21:00:47 +00:00
parent 5ed262b7de
commit ef1b50de6c
1 changed files with 17 additions and 0 deletions

View File

@ -1419,3 +1419,20 @@ C standard added additional format codes.
The exact range of years for which \method{strftime()} works also
varies across platforms. Regardless of platform, years before 1900
cannot be used.
\subsection{Examples}
\subsubsection{Creating Datetime Objects from Formatted Strings}
The \class{datetime} class does not directly support parsing formatted time
strings. You can use \function{time.strptime} to do the parsing and create
a \class{datetime} object from the tuple it returns:
\begin{verbatim}
>>> 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)
\end{verbatim}