A Python program can handle time in several ways. Time intervals are represented by floating-point numbers, in units of seconds (a fraction of a second is the fractional part of the interval). Particular instants in time are expressed in seconds since a reference instant, known as the epoch. (Midnight, UTC, of January 1, 1970, is a popular epoch used on both Unix and Windows platforms.) Time instants often also need to be expressed as a mixture of units of measurement (e.g., years, months, days, hours, minutes, and seconds), particularly for I/O purposes.
This chapter covers the
time module, which
supplies Python’s core time-handling functionality.
time module strongly depends on the system C
library. The chapter also presents the
calendar modules and the essentials of the popular
mx.DateTime has more uniform behavior across
time, which helps account for its
Python 2.3 will introduce a new
datetime module to manipulate dates and times in
other ways. At http://starship.python.net/crew/jbauer/normaldate/,
you can download Jeff Bauer’s
normalDate.py, which gains simplicity by dealing
only with dates, not with times. Neither of these modules is further
covered in this book.
The underlying C library determines the
range of dates that the
time module can handle. On
Unix systems, years 1970 and 2038 are the typical cut-off points, a
mx.DateTime lets you ...