:right-sidebar: True DateTime =================================================================== .. currentmodule:: gi.repository.GLib .. versionadded:: 2.26 .. class:: DateTime(**kwargs) :no-contents-entry: ``GDateTime`` is a structure that combines a Gregorian date and time into a single structure. ``GDateTime`` provides many conversion and methods to manipulate dates and times. Time precision is provided down to microseconds and the time can range (proleptically) from 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999. ``GDateTime`` follows POSIX time in the sense that it is oblivious to leap seconds. ``GDateTime`` is an immutable object; once it has been created it cannot be modified further. All modifiers will create a new ``GDateTime``\. Nearly all such functions can fail due to the date or time going out of range, in which case :const:`None` will be returned. ``GDateTime`` is reference counted: the reference count is increased by calling :obj:`~gi.repository.GLib.DateTime.ref` and decreased by calling :obj:`~gi.repository.GLib.DateTime.unref`\. When the reference count drops to 0, the resources allocated by the ``GDateTime`` structure are released. Many parts of the API may produce non-obvious results. As an example, adding two months to January 31st will yield March 31st whereas adding one month and then one month again will yield either March 28th or March 29th. Also note that adding 24 hours is not always the same as adding one day (since days containing daylight savings time transitions are either 23 or 25 hours in length). Constructors ------------ .. rst-class:: interim-class .. class:: DateTime :no-index: .. classmethod:: new(tz: ~gi.repository.GLib.TimeZone, year: int, month: int, day: int, hour: int, minute: int, seconds: float) -> ~gi.repository.GLib.DateTime | None Creates a new :obj:`~gi.repository.GLib.DateTime` corresponding to the given date and time in the time zone ``tz``\. The ``year`` must be between 1 and 9999, ``month`` between 1 and 12 and ``day`` between 1 and 28, 29, 30 or 31 depending on the month and the year. ``hour`` must be between 0 and 23 and ``minute`` must be between 0 and 59. ``seconds`` must be at least 0.0 and must be strictly less than 60.0. It will be rounded down to the nearest microsecond. If the given time is not representable in the given time zone (for example, 02:30 on March 14th 2010 in Toronto, due to daylight savings time) then the time will be rounded up to the nearest existing time (in this case, 03:00). If this matters to you then you should verify the return value for containing the same as the numbers you gave. In the case that the given time is ambiguous in the given time zone (for example, 01:30 on November 7th 2010 in Toronto, due to daylight savings time) then the time falling within standard (ie: non-daylight) time is taken. It not considered a programmer error for the values to this function to be out of range, but in the case that they are, the function will return :const:`None`. You should release the return value by calling :func:`~gi.repository.GLib.DateTime.unref` when you are done with it. .. versionadded:: 2.26 :param tz: a :obj:`~gi.repository.GLib.TimeZone` :param year: the year component of the date :param month: the month component of the date :param day: the day component of the date :param hour: the hour component of the date :param minute: the minute component of the date :param seconds: the number of seconds past the minute .. classmethod:: new_from_iso8601(text: str, default_tz: ~gi.repository.GLib.TimeZone | None = None) -> ~gi.repository.GLib.DateTime | None Creates a :obj:`~gi.repository.GLib.DateTime` corresponding to the given `ISO 8601 formatted string `__ ``text``\. ISO 8601 strings of the form ``