On this page
DateTime Objects
datetime模块提供了各种日期和时间对象。在使用任何这些Function之前,必须将头文件datetime.h
包含在您的源代码中(请注意Python.h
不包括此文件),并且必须调用PyDateTime_IMPORT
宏,通常将其作为模块初始化Function的一部分。该宏将指向 C 结构的指针放入静态变量PyDateTimeAPI
,该变量由以下宏使用。
Type-check macros:
- int
PyDate_Check
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_DateType
或子类型PyDateTime_DateType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyDate_CheckExact
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_DateType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyDateTime_Check
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_DateTimeType
或子类型PyDateTime_DateTimeType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyDateTime_CheckExact
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_DateTimeType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyTime_Check
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_TimeType
或子类型PyDateTime_TimeType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyTime_CheckExact
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_TimeType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyDelta_Check
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_DeltaType
或子类型PyDateTime_DeltaType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyDelta_CheckExact
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_DeltaType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyTZInfo_Check
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_TZInfoType
或子类型PyDateTime_TZInfoType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
- int
PyTZInfo_CheckExact
(PyObject ** ob *)- 如果* ob *类型为
PyDateTime_TZInfoType
,则返回 true。 * ob 不能为 NULL *。
- 如果* ob *类型为
2.4 版的新Function。
创建对象的宏:
- PyObject *
PyDate_FromDate
(int 年,int 月,int 天)- 返回值:新参考.
返回具有指定年,月和日的datetime.date
对象。
2.4 版的新Function。
- PyObject *
PyDateTime_FromDateAndTime
(int * year *,int * month *,int * day *,int * hour *,int * minute *,int * second *,int * usecond *)- 返回值:新参考.
返回具有指定的年,月,日,小时,分钟,秒和微秒的datetime.datetime
对象。
2.4 版的新Function。
- PyObject *
PyTime_FromTime
(int * hour *,int * minute *,int * second *,int * usecond *)- 返回值:新参考.
返回具有指定的小时,分钟,秒和微秒的datetime.time
对象。
2.4 版的新Function。
- PyObject *
PyDelta_FromDSU
(int * days *,int * seconds *,int * useconds *)- 返回值:新参考.
返回代表给定天数,秒和微秒的datetime.timedelta
对象。执行归一化,以使finally的微秒和秒数位于为datetime.timedelta
个对象记录的范围内。
2.4 版的新Function。
从日期对象提取字段的宏。参数必须是PyDateTime_Date
的实例,包括子类(例如PyDateTime_DateTime
)。参数不能为* NULL *,并且不检查类型:
- int
PyDateTime_GET_YEAR
(PyDateTime_Date ** o *)- 返回年份,作为一个正整数。
2.4 版的新Function。
- int
PyDateTime_GET_MONTH
(PyDateTime_Date ** o *)- 以 1 到 12 之间的整数形式返回月份。
2.4 版的新Function。
- int
PyDateTime_GET_DAY
(PyDateTime_Date ** o *)- 以 1 到 31 之间的整数形式返回日期。
2.4 版的新Function。
从日期时间对象提取字段的宏。参数必须是PyDateTime_DateTime
的实例,包括子类。参数不能为* NULL *,并且不检查类型:
- int
PyDateTime_DATE_GET_HOUR
(PyDateTime_DateTime ** o *)- 以 0 到 23 之间的整数形式返回小时。
2.4 版的新Function。
- int
PyDateTime_DATE_GET_MINUTE
(PyDateTime_DateTime ** o *)- 以 0 到 59 之间的整数形式返回分钟。
2.4 版的新Function。
- int
PyDateTime_DATE_GET_SECOND
(PyDateTime_DateTime ** o *)- 以 0 到 59 之间的整数形式返回第二个。
2.4 版的新Function。
- int
PyDateTime_DATE_GET_MICROSECOND
(PyDateTime_DateTime ** o *)- 返回微秒,作为一个从 0 到 999999 的整数。
2.4 版的新Function。
从时间对象中提取字段的宏。参数必须是PyDateTime_Time
的实例,包括子类。参数不能为* NULL *,并且不检查类型:
- int
PyDateTime_TIME_GET_HOUR
(PyDateTime_Time ** o *)- 以 0 到 23 之间的整数形式返回小时。
2.4 版的新Function。
- int
PyDateTime_TIME_GET_MINUTE
(PyDateTime_Time ** o *)- 以 0 到 59 之间的整数形式返回分钟。
2.4 版的新Function。
- int
PyDateTime_TIME_GET_SECOND
(PyDateTime_Time ** o *)- 以 0 到 59 之间的整数形式返回第二个。
2.4 版的新Function。
- int
PyDateTime_TIME_GET_MICROSECOND
(PyDateTime_Time ** o *)- 返回微秒,作为一个从 0 到 999999 的整数。
2.4 版的新Function。
宏,以方便实现 DB API 的模块:
给定一个适合传递给datetime.datetime.fromtimestamp()
的参数 Tuples,创建并返回一个新的datetime.datetime
对象。
2.4 版的新Function。
给定一个适合传递给datetime.date.fromtimestamp()
的参数 Tuples,创建并返回一个新的datetime.date
对象。
2.4 版的新Function。