]> granicus.if.org Git - python/commitdiff
add common usage example
authorSkip Montanaro <skip@pobox.com>
Tue, 6 Dec 2005 21:00:47 +0000 (21:00 +0000)
committerSkip Montanaro <skip@pobox.com>
Tue, 6 Dec 2005 21:00:47 +0000 (21:00 +0000)
Doc/lib/libdatetime.tex

index cbda4c45c94f996a846ff8e1b7fe2adf83271c00..4bba553ee7b91599991cd3778956d94e6abe08bb 100644 (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}
+