summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libdatetime.tex17
1 files changed, 17 insertions, 0 deletions
diff --git a/Doc/lib/libdatetime.tex b/Doc/lib/libdatetime.tex
index cbda4c4..4bba553 100644
--- a/Doc/lib/libdatetime.tex
+++ b/Doc/lib/libdatetime.tex
@@ -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}
+