The following classes provide a subset of the functionality of the Python 2.3 date, time and datetime Objects. If you want to do sophisticated date and time classes is it is reccommended that you use Python 2.3. These classes are designed only so that Python 2.2 users can still use date and time functionality in the web.database module.
Note: It should be noted that although the time and datetime classes have the ability to support microseconds, the web.database module only deals in whole seconds since some of the underlying databases do not support microseconds.
year, month, day) |
A date object represents a date (year, month and day) in an idealized calendar, the current Gregorian calendar indefinitely extended in both directions. January 1 of year 1 is called day number 1, January 2 of year 1 is called day number 2, and so on. This matches the definition of the "proleptic Gregorian" calendar in Dershowitz and Reingold's book Calendrical Calculations, where it's the base calendar for all computations. See the book for algorithms for converting between proleptic Gregorian ordinals and many other calendar systems.
All arguments are required. Arguments may be ints or longs, in the following ranges:
MINYEAR <=
year <= MAXYEAR
1 <=
month <= 12
1 <=
day <= number of days in the given month and year
If an argument outside those ranges is given, ValueError
is raised.
Instance Attributes:
MINYEAR
and MAXYEAR
inclusive.
[hour=0][,minute=0][,second=0][,microsecond=0]) |
A time object represents a (local) time of day, independent of any particular day.
All arguments are required. Arguments may be ints or longs, in the following ranges:
0 <=
hour < 24
0 <=
minute < 60
0 <=
second < 60
0 <=
microsecond < 1000000
If an argument outside those ranges is given, ValueError
is raised.
Instance Attributes:
range(24)
.
range(60)
.
range(60)
.
range(1000000)
.
year, month, day[,hour=0][,minute=0][,second=0][,microsecond=0]) |
A datetime object is a single object containing all the information from a date object and a time object. Like a date object, datetime assumes the current Gregorian calendar extended in both directions; like a time object, datetime assumes there are exactly 3600*24 seconds in every day.
All arguments are required. Arguments may be ints or longs, in the following ranges:
MINYEAR <=
year <= MAXYEAR
1 <=
month <= 12
1 <=
day <= number of days in the given month and year
0 <=
hour < 24
0 <=
minute < 60
0 <=
second < 60
0 <=
microsecond < 1000000
If an argument outside those ranges is given, ValueError
is raised.
Instance Attributes:
MINYEAR
and MAXYEAR
inclusive.
range(24)
.
range(60)
.
range(60)
.
range(1000000)
.
All classes have the following class methods:
) |
format) |
%a Locale's abbreviated weekday name. %A Locale's full weekday name. %b Locale's abbreviated month name. %B Locale's full month name. %c Locale's appropriate date and time representation. %d Day of the month as a decimal number [01,31]. %H Hour (24-hour clock) as a decimal number [00,23]. %I Hour (12-hour clock) as a decimal number [01,12]. %j Day of the year as a decimal number [001,366]. %m Month as a decimal number [01,12]. %M Minute as a decimal number [00,59]. %p Locale's equivalent of either AM or PM. %S Second as a decimal number [00,61]. (1) %U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. %w Weekday as a decimal number [0(Sunday),6]. %W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. %x Locale's appropriate date representation. %X Locale's appropriate time representation. %y Year without century as a decimal number [00,99]. %Y Year with century as a decimal number. %Z Time zone name (no characters if no time zone exists). %% A literal "%" character.
For example:
>>> datetime.datetime(2004,5,3,10,30,50).strftime('%x-%X') '05/03/04-10:30:50'
) |
time.localtime()
and do not represent anything.
) |
microseconds
are ignored.
>>> import web, datetime >>> datetime.date(2004,5,3).isoformat() '2004-05-03' >>> datetime.time(10,30,50,9).isoformat() # Microseconds are ignored '10:30:50' >>> datetime.datetime(2004,5,3,10,30,50).isoformat() '2004-05-03 10:30:50'