The datetime Module
datetime
provides classes representing date and time objects, which can be either aware of time zones or naïve (the default). Class tzinfo
is abstract: module datetime
supplies no implementation (for all the gory details, see http://docs.python.org/lib/datetime-tzinfo.html). (See module pytz
, in The pytz Module, for a good, simple implementation of tzinfo
, which lets you easily create aware objects.) All the types in module datetime
have immutable instances, so the instances’ attributes are all read-only and the instances can be keys in a dict
or items in a set
.
Class date
Class date
instances represent a date (no time of day in particular within that date), are always naïve, and assume the Gregorian calendar was always in effect. date
instances have three read-only integer attributes: year
, month
, and day
.
date |
Class |
fromordinal |
Returns a |
fromtimestamp |
Returns a |
today |
Returns a Instances of class |
Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.