The datetime package supplies classes for manipulating dates and times.

See description in the official Python docs.

Types

datetime

type

Represents date and time information.

Fields

year
int

The year value of the datetime object.

month
int

The month value of the datetime object.

day
int

The day value of the datetime object.

hour
int

The hour value of the datetime object.

minute
int

The minute value of the datetime object.

second
int

The second value of the datetime object.

microsecond
int

The microsecond value of the datetime object.

Methods

__init__
(year, month, day, hour, minute, second, microsecond) -> None

Class constructor (initializer for the data type).

timestamp
() -> float

Returns the total number of seconds since the Unix epoch.

weekday
() -> int

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

__add__
(delta) -> datetime.datetime

+ operator for datetime objects.

__sub__
(delta) -> datetime.datetime

- operator for datetime objects.

__sub__
(other) -> datetime.timedelta

- operator for datetime objects.

Static methods

utcfromtimestamp
(timestamp) -> datetime.datetime

Returns the UTC datetime corresponding to the POSIX timestamp.

strptime
(date_string, format) -> datetime.datetime

Returns a datetime corresponding to date_string, parsed according to format.


time

type

Represents a time of day, independent of any particular day.

Fields

hour
int

The hour value of the time object.

minute
int

The minute value of the time object.

second
int

The second value of the time object.

microsecond
int

The microsecond value of the time object.

Methods

__init__
(hour, minute, second, microsecond) -> None

Class constructor (initializer for the data type).

__add__
(delta) -> datetime.datetime

+ operator for time objects.

__sub__
(delta) -> datetime.datetime

- operator for time objects.


timedelta

type

A timedelta object represents a duration, the difference between two datetimes.

Fields

days
int

The days value of the timedelta object.

seconds
int

The seconds value of the timedelta object.

microseconds
int

The microseconds value of the timedelta object.

Methods

__init__
(days, seconds, microseconds, milliseconds, minutes, hours, weeks) -> None

Class constructor (initializer for the data type).

total_seconds
() -> float

Returns the total number of seconds contained in the duration.