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

宏訪問UTC單例:
PyObject *PyDateTime_TimeZone_UTC
返回表示 UTC 的時區(qū)單例,與 datetime.timezone.utc 為同一對象。
3.7 新版功能.
類型檢查宏:
int PyDate_Check(PyObject *ob)
如果 ob 為 PyDateTime_DateType 類型或 PyDateTime_DateType 的某個子類型則返回真值。 ob 不能為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyDate_CheckExact(PyObject *ob)
如果 ob 為 PyDateTime_DateType 類型則返回真值。 ob 不能為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyDateTime_Check(PyObject *ob)
如果 ob 為 PyDateTime_DateTimeType 類型或 PyDateTime_DateTimeType 的某個子類型則返回真值。 ob 不能為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyDateTime_CheckExact(PyObject *ob)
如果 ob 為 PyDateTime_DateTimeType 類型則返回真值。 ob 不能為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyTime_Check(PyObject *ob)
如果 ob 的類型是 PyDateTime_TimeType 或是 PyDateTime_TimeType 的子類型則返回真值。 ob 必須不為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyTime_CheckExact(PyObject *ob)
如果 ob 為 PyDateTime_TimeType 類型則返回真值。 ob 不能為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyDelta_Check(PyObject *ob)
如果 ob 為 PyDateTime_DeltaType 類型或 PyDateTime_DeltaType 的某個子類型則返回真值。 ob 不能為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyDelta_CheckExact(PyObject *ob)
如果 ob 為 PyDateTime_DeltaType 類型則返回真值。 ob 不能為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyTZInfo_Check(PyObject *ob)
如果 ob 的類型是 PyDateTime_TZInfoType 或是 PyDateTime_TZInfoType 的子類型則返回真值。 ob 必須不為 NULL。 此函數(shù)總是會成功執(zhí)行。
int PyTZInfo_CheckExact(PyObject *ob)
如果 ob 為 PyDateTime_TZInfoType 類型則返回真值。 ob 不能為 NULL。 此函數(shù)總是會成功執(zhí)行。
用于創(chuàng)建對象的宏:
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.
返回具有指定 year, month, day, hour, minute, second 和 microsecond 屬性的 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.
返回代表給定天、秒和微秒數(shù)的 datetime.timedelta 對象。 將執(zhí)行正規(guī)化操作以使最終的微秒和秒數(shù)處在 datetime.timedelta 對象的文檔指明的區(qū)間之內(nèi)。
PyObject *PyTimeZone_FromOffset(PyDateTime_DeltaType *offset)
Return value: New reference.
返回一個 datetime.timezone 對象,該對象具有以 offset 參數(shù)表示 的未命名固定時差。
3.7 新版功能.
PyObject *PyTimeZone_FromOffsetAndName(PyDateTime_DeltaType *offset, PyUnicode *name)
Return value: New reference.
返回一個 datetime.timezone 對象,該對象具有以 offset 參數(shù)表示的固定時差和時區(qū)名稱 name。
3.7 新版功能.
一些用來從 date 對象中提取字段的宏。 參數(shù)必須是 PyDateTime_Date 包括其子類 (例如 PyDateTime_DateTime) 的實例。 參數(shù)必須不為 NULL,并且類型不被會檢查:
int PyDateTime_GET_YEAR(PyDateTime_Date *o)
以正整數(shù)的形式返回年份值。
int PyDateTime_GET_MONTH(PyDateTime_Date *o)
返回月,從0到12的整數(shù)。
int PyDateTime_GET_DAY(PyDateTime_Date *o)
返回日期,從0到31的整數(shù)。
一些用來從 datetime 對象中提取字段的宏。 參數(shù)必須是 PyDateTime_DateTime 包括其子類的實例。 參數(shù)必須不為 NULL,并且類型不會被檢查:
int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o)
返回小時,從0到23的整數(shù)。
int PyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime *o)
返回分鐘,從0到59的整數(shù)。
int PyDateTime_DATE_GET_SECOND(PyDateTime_DateTime *o)
返回秒,從0到59的整數(shù)。
int PyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime *o)
返回微秒,從0到999999的整數(shù)。
int PyDateTime_DATE_GET_FOLD(PyDateTime_DateTime *o)
Return the fold, as an int from 0 through 1.
3.6 新版功能.
PyObject *PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)
返回 tzinfo (可以為 None)。
3.10 新版功能.
一些用來從 time 對象中提取字段的宏。 參數(shù)必須是 PyDateTime_Time 包括其子類的實例。 參數(shù)必須不為 NULL,并且類型不會被檢查:
int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o)
返回小時,從0到23的整數(shù)。
int PyDateTime_TIME_GET_MINUTE(PyDateTime_Time *o)
返回分鐘,從0到59的整數(shù)。
int PyDateTime_TIME_GET_SECOND(PyDateTime_Time *o)
返回秒,從0到59的整數(shù)。
int PyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time *o)
返回微秒,從0到999999的整數(shù)。
int PyDateTime_TIME_GET_FOLD(PyDateTime_Time *o)
Return the fold, as an int from 0 through 1.
3.6 新版功能.
PyObject *PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)
返回 tzinfo (可以為 None)。
3.10 新版功能.
一些用來從 timedelta 對象中提取字段的宏。 參數(shù)必須是 PyDateTime_Delta 包括其子類的實例。 參數(shù)必須不為 NULL,并且類型不會被檢查:
int PyDateTime_DELTA_GET_DAYS(PyDateTime_Delta *o)
返回天數(shù),從-999999999到999999999的整數(shù)。
3.3 新版功能.
int PyDateTime_DELTA_GET_SECONDS(PyDateTime_Delta *o)
返回秒數(shù),從0到86399的整數(shù)。
3.3 新版功能.
int PyDateTime_DELTA_GET_MICROSECONDS(PyDateTime_Delta *o)
返回微秒數(shù),從0到999999的整數(shù)。
3.3 新版功能.
一些便于模塊實現(xiàn) DB API 的宏:
PyObject *PyDateTime_FromTimestamp(PyObject *args)
Return value: New reference.
創(chuàng)建并返回一個給定元組參數(shù)的新 datetime.datetime 對象,適合傳給 datetime.datetime.fromtimestamp()。
PyObject *PyDate_FromTimestamp(PyObject *args)
Return value: New reference.
創(chuàng)建并返回一個給定元組參數(shù)的新 datetime.date 對象,適合傳給 datetime.date.fromtimestamp()。
網(wǎng)頁題目:創(chuàng)新互聯(lián)Python教程:DateTime對象
當前網(wǎng)址:http://www.dlmjj.cn/article/dpejjpe.html


咨詢
建站咨詢
