The datetime package supplies classes for manipulating dates and times.
Types
datetime
type
Represents date and time information.
Fields
The year value of the datetime object.
The month value of the datetime object.
The day value of the datetime object.
The hour value of the datetime object.
The minute value of the datetime object.
The second value of the datetime object.
The microsecond value of the datetime object.
Methods
__init__
(year, month, day, hour, minute, second, microsecond) -> None
Class constructor (initializer for the data type).
Returns the total number of seconds since the Unix epoch.
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.
delta
datetime.timedelta
requiredTimedelta to add to the current datetime.
__sub__
(delta) -> datetime.datetime
-
operator for datetime
objects.
delta
datetime.timedelta
requiredTimedelta to subtract from the current datetime.
__sub__
(other) -> datetime.timedelta
-
operator for datetime
objects.
other
datetime.datetime
requiredDatetime to subtract from the current datetime.
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
.
Datetime format. Supported codes: %Y
, %y
, %m
, %b
, %d
, %H
, %I
, %M
, %S
, %p
, %f
, %z
. See more details here.
time
type
Represents a time of day, independent of any particular day.
Fields
The hour value of the time object.
The minute value of the time object.
The second value of the time object.
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.
delta
datetime.timedelta
requiredTimedelta to add to the current time.
__sub__
(delta) -> datetime.datetime
-
operator for time
objects.
delta
datetime.timedelta
requiredTimedelta to subtract from the current time.
timedelta
type
A timedelta object represents a duration, the difference between two datetimes.
Fields
The days value of the timedelta object.
The seconds value of the timedelta object.
The microseconds value of the timedelta object.
Methods
__init__
(days, seconds, microseconds, milliseconds, minutes, hours, weeks) -> None
Class constructor (initializer for the data type).
Returns the total number of seconds contained in the duration.