This is a preview version of the DisplayLink DL-7450 Software Development Kit Documentation. The functionality that is described and made available in this version is subject to addition, removal or change without warning.

class datetime – Represent a date and time

class datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)

A datetime object is a single object containing all the information from a date object and a time object.

The arguments are as follows:

  • year, month, day, hour, minute, second and microsecond are integers in the given 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

    Each of these arguments will default to 0 if omitted.

  • tzinfo is a datetime.tzinfo object, allowing a datetime to be associated with a particular timezone. If this is not desired, the tzinfo can be None.

  • fold is a value of either 0 or 1 used to disambiguate wall times during a repeated interval. A repeated interval occurs when clocks are rolled back at the end of daylight saving time, or when the UTC offset for the current zone is decreased for political reasons. The values 0 and 1 represent, respectively, the earlier and later of the two moments with the same wall time representation.

classmethod fromisoformat()

Construct a datetime object from a string in ISO 8601 format:

from datetime import datetime
dt = datetime.fromisoformat('2012-12-21 07:55:27.999999')
classmethod fromordinal(ordinal)

Construct a datetime object representing the year, month and day specified by the provided ordinal.

An ordinal is an integer representing the number of days since January 1st of year 1.

The hour, minute, second, and microsecond arguments will all be set to 0, and tzinfo will be set to None.

classmethod fromtimestamp(timestamp, tz=None)

Construct a datetime object representing the year, month and day specified by the provided timestamp.

A timestamp in this case is a floating point number representing the number of seconds since the epoch (January 1, 1970, 00:00:00 UTC).

An optional tz argument may be provided to specify the timezone of the resulting datetime.

classmethod now(tz=None)

Construct a datetime object representing the current date and time.

An optional tz argument may be provided to specify the timezone of the resulting datetime.

classmethod combine(date, time, tzinfo=None)

Construct a datetime object from a date and time object.

The date and time arguments must be instances of date and time, respectively.

The tzinfo argument is optional and will be used to set the timezone of the resulting datetime. If not provided, the timezone (or lack thereof) will be inferred from the time argument.

EPOCH

A datetime object representing the Unix epoch (January 1, 1970, 00:00:00 UTC).

year

The year of the datetime, an integer in the range MINYEAR to MAXYEAR.

month

The month of the datetime, an integer in the range 1 to 12.

day

The day of the datetime, an integer in the range 1 to the number of days in the month represented by month.

hour

The hour of the datetime, an integer in the range 0 to 23.

minute

The minute of the datetime, an integer in the range 0 to 59.

second

The second of the datetime, an integer in the range 0 to 59.

microsecond

The microsecond of the datetime, an integer in the range 0 to 999999.

tzinfo

The datetime.tzinfo object associated with the datetime, or None if no timezone information is associated with the datetime.

fold

Used to disambiguate wall times during a repeated interval. The values 0 and 1 represent, respectively, the earlier and later of the two moments with the same wall time representation.

replace(year=self.year, month=self.year, day=self.year, hour=self.hour, minute=self.minute, second=self.second, microsecond=self.microsecond, tzinfo=self.tzinfo, *, fold=0)

Return a new datetime object with the same values as the existing datetime object, but with the specified parameters updated.

tuple()

Return the datetime as a 9-tuple (year, month, day, hour, minute, second, microsecond, tzinfo, fold).

astimezone(tz=None)

Return a datetime that represents the same point in time, relative to the specified timezone tz. The current datetime must already have an associated tzinfo, otherwise this method will raise a NotImplementedError.

date()

Return the date portion of the datetime as a date object. The resulting object will have no timezone information.

time()

Return the time portion of the datetime as a time object. The resulting object will have no timezone information.

timetz()

Return the time portion of the datetime as a time object. The resulting object will have the same timezone information as the original datetime.

dst()

Return the daylight savings time offset as a datetime.timedelta object, or None if the time has no associated timezone.

isoformat(sep='T', timespec='auto')

Return a string representing the datetime in ISO 8601 format.

By default, this will output the date and time in the format YYYY-MM-DDTHH:MM:SS (or YYYY-MM-DDTHH:MM:SS.ssssss if microsecond is not 0). The optional sep argument can be used to specify the separator between the date and time portions of the output string. The optional timespec argument can be used to specify the number of digits to include in the output string:

  • 'hours': YYYY-MM-DDTHH

  • 'minutes': YYYY-MM-DDTHH:MM

  • 'seconds': YYYY-MM-DDTHH:MM:SS

  • 'milliseconds': YYYY-MM-DDTHH:MM:SS.sss

  • 'microseconds': YYYY-MM-DDTHH:MM:SS.ssssss

isoweekday()

Return the day of the week as an integer, where Monday is 1 and Sunday is 7.

weekday()

Return the day of the week as an integer, where Monday is 0 and Sunday is 6.

timetuple()

Return the datetime as a 9-tuple (year, month, day, hour, minute, second, weekday, yearday, dst).

In this case:

  • weekday is the day of the week as an integer, where Monday is 0 and Sunday is 6.

  • yearday is the day of the year as an integer, where January 1st is 1.

  • dst is -1 if there is no associated timezone, 0 if the associated timezone does not observe daylight savings time, or 1 if it does.

toordinal()

Return an integer representing the ordinal of the date, where January 1st of year 1 has ordinal 1.

tzname()

Return the name of the timezone as a string, or None if the datetime has no associated timezone.

utcoffset()

Return the UTC offset as a datetime.timedelta object, or None if the datetime has no associated timezone.