[Python-checkins] commit of r41632 - python/trunk/Doc/lib/libdatetime.tex

skip.montanaro python-checkins at python.org
Tue Dec 6 22:00:50 CET 2005


Author: skip.montanaro
Date: Tue Dec  6 22:00:47 2005
New Revision: 41632

Modified:
   python/trunk/Doc/lib/libdatetime.tex
Log:
add common usage example

Modified: python/trunk/Doc/lib/libdatetime.tex
==============================================================================
--- python/trunk/Doc/lib/libdatetime.tex	(original)
+++ python/trunk/Doc/lib/libdatetime.tex	Tue Dec  6 22:00:47 2005
@@ -1419,3 +1419,20 @@
 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}
+


More information about the Python-checkins mailing list