Mercurial > cpython-lru_cache-weakref
diff Doc/lib/libdatetime.tex @ 35996:dbcc8912a24d legacy-trunk
add common usage example
| author | Skip Montanaro <skip@pobox.com> |
|---|---|
| date | Tue, 06 Dec 2005 21:00:47 +0000 |
| parents | a063f0d6db28 |
| children | 5203376f1589 |
line wrap: on
line diff
--- a/Doc/lib/libdatetime.tex Tue Dec 06 18:32:37 2005 +0000 +++ b/Doc/lib/libdatetime.tex Tue Dec 06 21:00:47 2005 +0000 @@ -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} +
