DateTime 對象?

datetime 模塊提供了各種日期和時間對象。 在使用任何這些函數之前,必須在你的源碼中包含頭文件 datetime.h (請注意此文件并未包含在 Python.h 中),并且宏 PyDateTime_IMPORT 必須被發起調用,通常是作為模塊初始化函數的一部分。 這個宏會將指向特定 C 結構的指針放入一個靜態變量 PyDateTimeAPI 中,它會由下面的宏來使用。

宏訪問UTC單例:

PyObject* PyDateTime_TimeZone_UTC?

返回表示 UTC 的時區單例,與 datetime.timezone.utc 為同一對象。

3.7 新版功能.

類型檢查宏:

int PyDate_Check(PyObject?*ob)?

如果 obPyDateTime_DateType 類型或 PyDateTime_DateType 的某個子類型則返回真值。 ob 不能為 NULL

int PyDate_CheckExact(PyObject?*ob)?

如果 obPyDateTime_DateType 類型則返回真值。 ob 不能為 NULL

int PyDateTime_Check(PyObject?*ob)?

如果 obPyDateTime_DateTimeType 類型或 PyDateTime_DateTimeType 的某個子類型則返回真值。 ob 不能為 NULL

int PyDateTime_CheckExact(PyObject?*ob)?

如果 obPyDateTime_DateTimeType 類型則返回真值。 ob 不能為 NULL

int PyTime_Check(PyObject?*ob)?

如果 ob 的類型是 PyDateTime_TimeType 或是 PyDateTime_TimeType 的子類型則返回真值。 ob 必須不為 NULL

int PyTime_CheckExact(PyObject?*ob)?

如果 ob 的類型為 PyDateTime_TimeType 則返回真值。 ob 必須不為 NULL

int PyDelta_Check(PyObject?*ob)?

如果 obPyDateTime_DeltaType 類型或 PyDateTime_DeltaType 的某個子類型則返回真值。 ob 不能為 NULL

int PyDelta_CheckExact(PyObject?*ob)?

如果 obPyDateTime_DeltaType 類型則返回真值。 ob 不能為 NULL

int PyTZInfo_Check(PyObject?*ob)?

如果 obPyDateTime_TZInfoType 類型或 PyDateTime_TZInfoType 的某個子類型則返回真值。 ob 必須不為 NULL

int PyTZInfo_CheckExact(PyObject?*ob)?

如果 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.

返回具有指定 year, month, day, hour, minute, second, microsecond 和 fold 屬性的 datetime.datetime 對象。

3.6 新版功能.

PyObject* PyTime_FromTime(int?hour, int?minute, int?second, int?usecond)?
Return value: New reference.

返回具有指定 hour, minute, second and microsecond 屬性的 datetime.time 對象。

PyObject* PyTime_FromTimeAndFold(int?hour, int?minute, int?second, int?usecond, int?fold)?
Return value: New reference.

返回具有指定 hour, minute, second, microsecond 和 fold 屬性的 datetime.time 對象。

3.6 新版功能.

PyObject* PyDelta_FromDSU(int?days, int?seconds, int?useconds)?
Return value: New reference.

返回代表給定天、秒和微秒數的 datetime.timedelta 對象。 將執行正規化操作以使最終的微秒和秒數處在 datetime.timedelta 對象的文檔指明的區間之內。

PyObject* PyTimeZone_FromOffset(PyDateTime_DeltaType*?offset)?
Return value: New reference.

返回一個 datetime.timezone 對象,該對象帶有以 offset 參數表示 的未命名固定時差。

3.7 新版功能.

PyObject* PyTimeZone_FromOffsetAndName(PyDateTime_DeltaType*?offset, PyUnicode*?name)?
Return value: New reference.

返回一個 datetime.timezone 對象,該對象具有以 offset 參數表示的固定時差和時區名稱 name

3.7 新版功能.

一些用來從 date 對象中提取字段的宏。 參數必須是 PyDateTime_Date 包括其子類 (例如 PyDateTime_DateTime) 的實例。 參數必須不為 NULL,并且類型不被會檢查:

int PyDateTime_GET_YEAR(PyDateTime_Date?*o)?

以正整數的形式返回年份值。

int PyDateTime_GET_MONTH(PyDateTime_Date?*o)?

返回月,從0到12的整數。

int PyDateTime_GET_DAY(PyDateTime_Date?*o)?

返回日期,從0到31的整數。

一些用來從 datetime 對象中提取字段的宏。 參數必須是 PyDateTime_DateTime 包括其子類的實例。 參數必須不為 NULL,并且類型不會被檢查:

int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime?*o)?

返回小時,從0到23的整數。

int PyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime?*o)?

返回分鐘,從0到59的整數。

int PyDateTime_DATE_GET_SECOND(PyDateTime_DateTime?*o)?

返回秒,從0到59的整數。

int PyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime?*o)?

返回微秒,從0到999999的整數。

一些用來從 time 對象中提取字段的宏。 參數必須是 PyDateTime_Time 包括其子類的實例。 參數必須不為 NULL,并且類型不會被檢查:

int PyDateTime_TIME_GET_HOUR(PyDateTime_Time?*o)?

返回小時,從0到23的整數。

int PyDateTime_TIME_GET_MINUTE(PyDateTime_Time?*o)?

返回分鐘,從0到59的整數。

int PyDateTime_TIME_GET_SECOND(PyDateTime_Time?*o)?

返回秒,從0到59的整數。

int PyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time?*o)?

返回微秒,從0到999999的整數。

一些用來從 timedelta 對象中提取字段的宏。 參數必須是 PyDateTime_Delta 包括其子類的實例。 參數必須不為 NULL,并且類型不會被檢查:

int PyDateTime_DELTA_GET_DAYS(PyDateTime_Delta?*o)?

返回天數,從-999999999到999999999的整數。

3.3 新版功能.

int PyDateTime_DELTA_GET_SECONDS(PyDateTime_Delta?*o)?

返回秒數,從0到86399的整數。

3.3 新版功能.

int PyDateTime_DELTA_GET_MICROSECONDS(PyDateTime_Delta?*o)?

返回微秒數,從0到999999的整數。

3.3 新版功能.

一些便于模塊實現 DB API 的宏:

PyObject* PyDateTime_FromTimestamp(PyObject?*args)?
Return value: New reference.

創建并返回一個給定元組參數的新 datetime.datetime 對象,適合傳給 datetime.datetime.fromtimestamp()

PyObject* PyDate_FromTimestamp(PyObject?*args)?
Return value: New reference.

創建并返回一個給定元組參數的新 datetime.date 對象,適合傳給 datetime.date.fromtimestamp()