XmlDateTime#

class xsdata.models.datatype.XmlDateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, fractional_second: int = 0, offset: int | None = None)[source]#

Concrete xs:dateTime builtin type.

Represents iso 8601 date time format [-]CCYY-MM-DDThh:mm: ss[Z|(+|-)hh:mm] with rich comparisons and hashing.

Parameters:
  • year – Any signed integer, eg (0, -535, 2020)

  • month – Unsigned integer between 1-12

  • day – Unsigned integer between 1-31

  • hour – Unsigned integer between 0-24

  • minute – Unsigned integer between 0-59

  • second – Unsigned integer between 0-59

  • fractional_second – Unsigned integer between 0-999999999

  • offset – Signed integer representing timezone offset in minutes

year: int#

Alias for field number 0

month: int#

Alias for field number 1

day: int#

Alias for field number 2

hour: int#

Alias for field number 3

minute: int#

Alias for field number 4

second: int#

Alias for field number 5

fractional_second: int#

Alias for field number 6

offset: Optional[int]#

Alias for field number 7

property microsecond: int#

Calculate the instance microseconds.

property duration: float#

Calculate the instance signed duration in seconds.

classmethod from_string(string)[source]#

Initialize from string with format %Y-%m-%dT%H:%M:%S%z.

Return type:

XmlDateTime

classmethod from_datetime(obj)[source]#

Initialize from datetime.datetime instance.

Return type:

XmlDateTime

classmethod now(tz=None)[source]#

Initialize with the current datetime and the given timezone.

Return type:

XmlDateTime

classmethod utcnow()[source]#

Initialize with the current datetime and utc timezone.

Return type:

XmlDateTime

to_datetime()[source]#

Return a datetime.datetime instance.

Return type:

datetime

replace(year=None, month=None, day=None, hour=None, minute=None, second=None, fractional_second=None, offset=True)[source]#

Return a new instance replacing the specified fields with new values.

Return type:

XmlDateTime

__str__()[source]#

Return the datetime formatted according to ISO 8601 for xml.

Return type:

str

Examples

  • 2001-10-26T21:32:52

  • 2001-10-26T21:32:52+02:00

  • 2001-10-26T19:32:52Z

  • 2001-10-26T19:32:52.126789

  • 2001-10-26T21:32:52.126

  • -2001-10-26T21:32:52.126Z

__eq__(other)[source]#

Return self == other.

Return type:

bool

__ne__(other)[source]#

Return self != other.

Return type:

bool

__lt__(other)[source]#

Return self < other.

Return type:

bool

__le__(other)[source]#

Return self <= other.

Return type:

bool

__gt__(other)[source]#

Return self > other.

Return type:

bool

__ge__(other)[source]#

Return self >= other.

Return type:

bool

__add__(value, /)#

Return self+value.

__contains__(key, /)#

Return key in self.

__getattribute__(name, /)#

Return getattr(self, name).

__getitem__(key, /)#

Return self[key].

__getnewargs__()#

Return self as a plain tuple. Used by copy and pickle.

__hash__()#

Return hash(self).

__iter__()#

Implement iter(self).

__len__()#

Return len(self).

__mul__(value, /)#

Return self*value.

__rmul__(value, /)#

Return value*self.

count(value, /)#

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.