日期时间对象¶
各种日期和时间对象由 datetime
模块。在使用这些函数之前,头文件 datetime.h
必须包含在源中(请注意,此项不包含在 Python.h
)和宏 PyDateTime_IMPORT
必须调用,通常作为模块初始化功能的一部分。宏将指向C结构的指针放入静态变量, PyDateTimeAPI
,由以下宏使用。
用于访问 UTC Singleton的宏:
-
PyObject *PyDateTime_TimeZone_UTC¶
返回表示UTC的时区单例,对象与
datetime.timezone.utc
.3.7 新版功能.
类型检查宏:
-
int PyDate_Check(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_DateType
或其子类型PyDateTime_DateType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyDate_CheckExact(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_DateType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyDateTime_Check(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_DateTimeType
或其子类型PyDateTime_DateTimeType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyDateTime_CheckExact(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_DateTimeType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyTime_Check(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_TimeType
或其子类型PyDateTime_TimeType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyTime_CheckExact(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_TimeType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyDelta_Check(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_DeltaType
或其子类型PyDateTime_DeltaType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyDelta_CheckExact(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_DeltaType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyTZInfo_Check(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_TZInfoType
或其子类型PyDateTime_TZInfoType
。 ob 一定不能是NULL
。此功能总是成功的。
-
int PyTZInfo_CheckExact(PyObject *ob)¶
如果满足以下条件,则返回TRUE ob 类型为
PyDateTime_TZInfoType
。 ob 一定不能是NULL
。此功能总是成功的。
创建对象的宏:
-
PyObject *PyDate_FromDate(int year, int month, int day)¶
- Return value: New reference.
返回A
datetime.date
具有指定的年、月和日的对象。
-
PyObject *PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)¶
- Return value: New reference.
返回A
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.
返回A
datetime.datetime
对象具有指定的年、月、日、小时、分钟、秒、微秒和折叠。3.6 新版功能.
-
PyObject *PyTime_FromTime(int hour, int minute, int second, int usecond)¶
- Return value: New reference.
返回A
datetime.time
具有指定的小时、分钟、秒和微秒的对象。
-
PyObject *PyTime_FromTimeAndFold(int hour, int minute, int second, int usecond, int fold)¶
- Return value: New reference.
返回A
datetime.time
对象具有指定的小时、分钟、秒、微秒和折叠。3.6 新版功能.
-
PyObject *PyDelta_FromDSU(int days, int seconds, int useconds)¶
- Return value: New reference.
返回A
datetime.timedelta
对象,表示给定的天、秒和微秒数。执行标准化,以使产生的微秒和秒数在记录的范围内。datetime.timedelta
物体。
-
PyObject *PyTimeZone_FromOffset(PyDateTime_DeltaType *offset)¶
- Return value: New reference.
返回A
datetime.timezone
对象,其未命名的固定偏移量由 抵消 参数。3.7 新版功能.
-
PyObject *PyTimeZone_FromOffsetAndName(PyDateTime_DeltaType *offset, PyUnicode *name)¶
- Return value: New reference.
返回A
datetime.timezone
具有固定偏移量的对象 抵消 参数和TzName name .3.7 新版功能.
用于从日期对象中提取字段的宏。参数必须是的实例 PyDateTime_Date
包括子类(如 PyDateTime_DateTime
)参数不能是 NULL
,不检查类型:
-
int PyDateTime_GET_YEAR(PyDateTime_Date *o)¶
返回年份,作为正整数。
-
int PyDateTime_GET_MONTH(PyDateTime_Date *o)¶
返回月份,作为从1到12的整数。
-
int PyDateTime_GET_DAY(PyDateTime_Date *o)¶
返回当天,作为从1到31的整数。
用于从日期时间对象中提取字段的宏。参数必须是的实例 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之间的整数形式返回微秒。
从时间对象中提取字段的宏。参数必须是的实例 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之间的整数形式返回微秒。
从时间增量对象中提取字段的宏。参数必须是的实例 PyDateTime_Delta
包括子类。参数不能是 NULL
,不检查类型:
-
int PyDateTime_DELTA_GET_DAYS(PyDateTime_Delta *o)¶
返回天数,以-99999999到99999999之间的整数表示。
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()
.