Text of docs.python.org › uk › 3 › c-api › datetime.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Об’єкти DateTime — Python 3.15.2 documentation

Навігація індекс модулі | наступний | попередній | Python » 3.15.2 documentation » Python/C API reference manual » Шар бетонних об’єктів » Об’єкти DateTime | Theme | Об’єкти DateTime ¶ Various date and time objects are supplied by the datetime module. Before using any of these functions, the header file datetime.h must be included in your source (note that this is not included by Python.h ), and the macro PyDateTime_IMPORT must be invoked, usually as part of the module initialisation function.

The macro puts a pointer to a C structure into a static variable, PyDateTimeAPI , that is used by the following macros. PyDateTime_IMPORT ¶ Import the datetime C API. On success, populate the PyDateTimeAPI pointer. On failure, set PyDateTimeAPI to NULL and set an exception. The caller must check if an error occurred via PyErr_Occurred() : PyDateTime_IMPORT ; if ( PyErr_Occurred ()) { /* cleanup */ } Попередження This is not compatible with subinterpreters.

Змінено в версії 3.15: This macro is now thread safe. type PyDateTime_CAPI ¶ Structure containing the fields for the datetime C API. The fields of this structure are private and subject to change. Do not use this directly; prefer PyDateTime_* APIs instead. PyDateTime_CAPI * PyDateTimeAPI ¶ Dynamically allocated object containing the datetime C API. This variable is only available once PyDateTime_IMPORT succeeds.

Змінено в версії 3.15: This variable should not be accessed directly as direct access is not thread-safe. Use PyDateTime_IMPORT instead. type PyDateTime_Date ¶ Цей підтип PyObject представляє об’єкт date в Python. type PyDateTime_DateTime ¶ Цей підтип PyObject представляє об’єкт datetime в Python. type PyDateTime_Time ¶ Цей підтип PyObject представляє об’єкт time в Python. type PyDateTime_Delta ¶ Цей підтип PyObject представляє різницю між двома значеннями datetime.

PyTypeObject PyDateTime_DateType ¶ This instance of PyTypeObject represents the Python date type; it is the same object as datetime.date in the Python layer. PyTypeObject PyDateTime_DateTimeType ¶ This instance of PyTypeObject represents the Python datetime type; it is the same object as datetime.datetime in the Python layer. PyTypeObject PyDateTime_TimeType ¶ This instance of PyTypeObject represents the Python time type; it is the same object as datetime.time in the Python layer.

PyTypeObject PyDateTime_DeltaType ¶ This instance of PyTypeObject represents the Python type for the difference between two datetime values; it is the same object as datetime.timedelta in the Python layer. PyTypeObject PyDateTime_TZInfoType ¶ This instance of PyTypeObject represents the Python time zone info type; it is the same object as datetime.tzinfo in the Python layer. Макрос для доступу до синглтону UTC: PyObject * PyDateTime_TimeZone_UTC ¶ Повертає синглтон часового поясу, який представляє UTC, той самий об’єкт, що й datetime.timezone.utc .

Added in version 3.7. Макроси перевірки типу: int PyDate_Check ( PyObject * ob ) ¶ Return true if ob is of type PyDateTime_DateType or a subtype of PyDateTime_DateType . ob must not be NULL . This function always succeeds. int PyDate_CheckExact ( PyObject * ob ) ¶ Повертає true, якщо ob має тип PyDateTime_DateType . ob не має бути NULL . Ця функція завжди успішна. int PyDateTime_Check ( PyObject * ob ) ¶ Return true if ob is of type PyDateTime_DateTimeType or a subtype of PyDateTime_DateTimeType . ob must not be NULL .

This function always succeeds. int PyDateTime_CheckExact ( PyObject * ob ) ¶ Повертає true, якщо ob має тип PyDateTime_DateTimeType . ob не має бути NULL . Ця функція завжди успішна. int PyTime_Check ( PyObject * ob ) ¶ Return true if ob is of type PyDateTime_TimeType or a subtype of PyDateTime_TimeType . ob must not be NULL . This function always succeeds. int PyTime_CheckExact ( PyObject * ob ) ¶ Повертає true, якщо ob має тип PyDateTime_TimeType . ob не має бути NULL .

Ця функція завжди успішна. int PyDelta_Check ( PyObject * ob ) ¶ Return true if ob is of type PyDateTime_DeltaType or a subtype of PyDateTime_DeltaType . ob must not be NULL . This function always succeeds. int PyDelta_CheckExact ( PyObject * ob ) ¶ Повертає true, якщо ob має тип PyDateTime_DeltaType . ob не має бути NULL . Ця функція завжди успішна. int PyTZInfo_Check ( PyObject * ob ) ¶ Return true if ob is of type PyDateTime_TZInfoType or a subtype of PyDateTime_TZInfoType . ob must not be NULL .

This function always succeeds. int PyTZInfo_CheckExact ( PyObject * ob ) ¶ Повертає true, якщо ob має тип PyDateTime_TZInfoType . ob не має бути NULL . Ця функція завжди успішна. Макроси для створення об’єктів: PyObject * PyDate_FromDate ( int year , int month , int day ) ¶ Return value: New reference. Повертає об’єкт datetime.date із зазначеним роком, місяцем і днем.

PyObject * PyDateTime_FromDateAndTime ( int year , int month , int day , int hour , int minute , int second , int usecond ) ¶ Return value: New reference. Повертає об’єкт datetime.datetime із вказаним роком, місяцем, днем, годиною, хвилиною, секундою та мікросекундою. PyObject * PyDateTime_FromDateAndTimeAndFold ( int year , int month , int day , int hour , int minute , int second , int usecond , int fold ) ¶ Return value: New reference.

Повертає об’єкт datetime.datetime із вказаним роком, місяцем, днем, годиною, хвилиною, секундою, мікросекундою та кратністю. Added in version 3.6. PyObject * PyTime_FromTime ( int hour , int minute , int second , int usecond ) ¶ Return value: New reference. Повертає об’єкт datetime.time із вказаною годиною, хвилиною, секундою та мікросекундою.

PyObject * PyTime_FromTimeAndFold ( int hour , int minute , int second , int usecond , int fold ) ¶ Return value: New reference. Повертає об’єкт datetime.time із вказаною годиною, хвилиною, секундою, мікросекундою та кратністю. Added in version 3.6. PyObject * PyDelta_FromDSU ( int days , int seconds , int useconds ) ¶ Return value: New reference.

Повертає об’єкт datetime.timedelta , що представляє задану кількість днів, секунд і мікросекунд. Нормалізація виконується таким чином, щоб результуюча кількість мікросекунд і секунд лежала в діапазонах, задокументованих для об’єктів datetime.timedelta .

PyObject * PyTimeZone_FromOffset ( PyObject * offset ) ¶ Return value: New reference. Повертає об’єкт datetime.timezone із фіксованим зсувом без назви, представленим аргументом offset . Added in version 3.7. PyObject * PyTimeZone_FromOffsetAndName ( PyObject * offset , PyObject * name ) ¶ Return value: New reference. Повертає об’єкт datetime.timezone із фіксованим зсувом, представленим аргументом offset , і з tzname name .

Added in version 3.7. Macros to extract fields from date objects. The argument must be an instance o

The rest of this page is on the live site.