diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2003-01-13 19:09:03 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2003-01-13 19:09:03 (GMT) |
commit | a974b3939f8f6239018fd0de44530244812191da (patch) | |
tree | bd8fa620313269f215e5e3a625309837b5062e2a | |
parent | 07f9398dc949614d54d4fdc61a0be04d6a7fd700 (diff) | |
download | cpython-a974b3939f8f6239018fd0de44530244812191da.zip cpython-a974b3939f8f6239018fd0de44530244812191da.tar.gz cpython-a974b3939f8f6239018fd0de44530244812191da.tar.bz2 |
Move the date/time section into the modules section; it was in the
C API section by mistake
-rw-r--r-- | Doc/whatsnew/whatsnew23.tex | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/Doc/whatsnew/whatsnew23.tex b/Doc/whatsnew/whatsnew23.tex index 26a8e30..ce997cc 100644 --- a/Doc/whatsnew/whatsnew23.tex +++ b/Doc/whatsnew/whatsnew23.tex @@ -1648,6 +1648,67 @@ Any breakage caused by this change should be reported as a bug. %====================================================================== +\subsection{Date/Time Type} + +Date and time types suitable for expressing timestamps were added as +the \module{datetime} module. The types don't support different +calendars or many fancy features, and just stick to the basics of +representing time. + +The three primary types are: \class{date}, representing a day, month, +and year; \class{time}, consisting of hour, minute, and second; and +\class{datetime}, which contains all the attributes of both +\class{date} and \class{time}. These basic types don't understand +time zones, but there are subclasses named \class{timetz} and +\class{datetimetz} that do. There's also a +\class{timedelta} class representing a difference between two points +in time, and time zone logic is implemented by classes inheriting from +the abstract \class{tzinfo} class. + +You can create instances of \class{date} and \class{time} by either +supplying keyword arguments to the appropriate constructor, +e.g. \code{datetime.date(year=1972, month=10, day=15)}, or by using +one of a number of class methods. For example, the \method{today()} +class method returns the current local date. + +Once created, instances of the date/time classes are all immutable. +There are a number of methods for producing formatted strings from +objects: + +\begin{verbatim} +>>> import datetime +>>> now = datetime.datetime.now() +>>> now.isoformat() +'2002-12-30T21:27:03.994956' +>>> now.ctime() # Only available on date, datetime +'Mon Dec 30 21:27:03 2002' +>>> now.strftime('%Y %d %h') +'2002 30 Dec' +\end{verbatim} + +The \method{replace()} method allows modifying one or more fields +of a \class{date} or \class{datetime} instance: + +\begin{verbatim} +>>> d = datetime.datetime.now() +>>> d +datetime.datetime(2002, 12, 30, 22, 15, 38, 827738) +>>> d.replace(year=2001, hour = 12) +datetime.datetime(2001, 12, 30, 12, 15, 38, 827738) +>>> +\end{verbatim} + +Instances can be compared, hashed, and converted to strings (the +result is the same as that of \method{isoformat()}). \class{date} and +\class{datetime} instances can be subtracted from each other, and +added to \class{timedelta} instances. + +For more information, refer to the \ulink{module's reference +documentation}{http://www.python.org/dev/doc/devel/lib/module-datetime.html}. +(Contributed by Tim Peters.) + + +%====================================================================== \subsection{The \module{optparse} Module} The \module{getopt} module provides simple parsing of command-line @@ -1905,67 +1966,6 @@ Expat. %====================================================================== -\subsection{Date/Time Type} - -Date and time types suitable for expressing timestamps were added as -the \module{datetime} module. The types don't support different -calendars or many fancy features, and just stick to the basics of -representing time. - -The three primary types are: \class{date}, representing a day, month, -and year; \class{time}, consisting of hour, minute, and second; and -\class{datetime}, which contains all the attributes of both -\class{date} and \class{time}. These basic types don't understand -time zones, but there are subclasses named \class{timetz} and -\class{datetimetz} that do. There's also a -\class{timedelta} class representing a difference between two points -in time, and time zone logic is implemented by classes inheriting from -the abstract \class{tzinfo} class. - -You can create instances of \class{date} and \class{time} by either -supplying keyword arguments to the appropriate constructor, -e.g. \code{datetime.date(year=1972, month=10, day=15)}, or by using -one of a number of class methods. For example, the \method{today()} -class method returns the current local date. - -Once created, instances of the date/time classes are all immutable. -There are a number of methods for producing formatted strings from -objects: - -\begin{verbatim} ->>> import datetime ->>> now = datetime.datetime.now() ->>> now.isoformat() -'2002-12-30T21:27:03.994956' ->>> now.ctime() # Only available on date, datetime -'Mon Dec 30 21:27:03 2002' ->>> now.strftime('%Y %d %h') -'2002 30 Dec' -\end{verbatim} - -The \method{replace()} method allows modifying one or more fields -of a \class{date} or \class{datetime} instance: - -\begin{verbatim} ->>> d = datetime.datetime.now() ->>> d -datetime.datetime(2002, 12, 30, 22, 15, 38, 827738) ->>> d.replace(year=2001, hour = 12) -datetime.datetime(2001, 12, 30, 12, 15, 38, 827738) ->>> -\end{verbatim} - -Instances can be compared, hashed, and converted to strings (the -result is the same as that of \method{isoformat()}). \class{date} and -\class{datetime} instances can be subtracted from each other, and -added to \class{timedelta} instances. - -For more information, refer to the \ulink{module's reference -documentation}{http://www.python.org/dev/doc/devel/lib/module-datetime.html}. -(Contributed by Tim Peters.) - - -%====================================================================== \subsection{Port-Specific Changes} Support for a port to IBM's OS/2 using the EMX runtime environment was |