summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libdatetime.tex
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2005-12-06 21:00:47 (GMT)
committerSkip Montanaro <skip@pobox.com>2005-12-06 21:00:47 (GMT)
commitef1b50de6c6113bf47719634a22eabe3a2635ef8 (patch)
treef9fb0eea5e1d5cbb6e0b9f04ec40ff2a24917200 /Doc/lib/libdatetime.tex
parent5ed262b7de5661dd71fad5e4e0f417a56acfc6eb (diff)
downloadcpython-ef1b50de6c6113bf47719634a22eabe3a2635ef8.zip
cpython-ef1b50de6c6113bf47719634a22eabe3a2635ef8.tar.gz
cpython-ef1b50de6c6113bf47719634a22eabe3a2635ef8.tar.bz2
add common usage example
Diffstat (limited to 'Doc/lib/libdatetime.tex')
-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}
+