cf.Datetime

class cf.Datetime(year, month, day, hour=0, minute=0, second=0, dayofwk=-1, dayofyr=1)[source]

Bases: object

A datetime object which supports CF calendars.

Any date and time valid in any CF calendar is allowed.

In many situations, it may be used interchangably with a built-in datetime.datetime object. For example:

>>> import datetime
>>> d = cf.Datetime(2004, 2, 30)
>>> d > datetime.datetime(2004, 2, 1)
True

Attributes

Attribute Description
year The year of the date
month The month of the year of the date
day The day of the month of the date
hour The hour of the day of the date
minute The minute of the hour of the date
second The second of the minute of the date

Initialization

Parameters :
year, month, day : ints

The date.

hour, minute, second : ints, optional

The time of the date. Any unspecified value defaults to 0.

Examples

>>> d = cf.Datetime(2003, 2, 30)
>>> d = cf.Datetime(2003, 2, 30, 0)
>>> d = cf.Datetime(2003, 2, 30, 0, 0)
>>> d = cf.Datetime(2003, 2, 30, 0, 0, 0)
>>> d = cf.Datetime(2003, 4, 5, 12, 30, 15)
>>> d = cf.Datetime(year=2003, month=4, day=5, hour=12, minute=30, second=15)
>>> d.year, d.month, d.day, d.hour, d.minute, d.second
(2003, 4, 5, 12, 30, 15)
>>> d.timetuple()
(2003, 4, 5, 12, 30, 15, -1, 1)

Datetime methods

copy Return a deep copy.
timetuple Return a tuple of the datetime attributes.

Datetime class methods

utcnow Return the current Gregorian calendar UTC date and time.

Table Of Contents

Previous topic

cf.Comparison.evaluate

Next topic

cf.Datetime.copy

This Page