DateTime Objects

各种日期和时间对象由datetime模块提供。在使用任何这些函数之前,头文件datetime.h必须包含在你的来源中(注意这不包含在Python.h中)和宏PyDateTime_IMPORT必须调用,通常作为模块初始化函数的一部分。宏将一个指向C结构的指针放到一个静态变量PyDateTimeAPI中,由下面的macros使用

用于访问UTC singleton的宏:

PyObject * PyDateTime_TimeZone_UTC
返回表示UTC的时区单例,与datetime.timezone.utc.

相同的对象,版本3.7.

Type-check macros:

int PyDate_Check(的PyObject  *ob)
如果ob是PyDateTime_DateType或的子类型PyDateTime_DateType. ob必须不 NULL.
int PyDate_CheckExact(的PyObject  *ob)
如果ob是PyDateTime_DateType. ob必须不NULL.
int PyDateTime_Check(的PyObject  *ob)
如果ob是PyDateTime_DateTimeType或的子类型PyDateTime_DateTimeType. ob必须不 NULL.
int PyDateTime_CheckExact(的PyObject  *ob)
如果ob是PyDateTime_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)
如果ob属于PyDateTime_DeltaType或PyDateTime_DeltaType. ob的子类型不能NULL.
// PyDelta_CheckExact( PyObject  *ob)
如果ob是PyDateTime_DeltaType. ob必须不NULL.
int PyTZInfo_Check(的PyObject  *ob)
如果ob是PyDateTime_TZInfoType或的子类型PyDateTime_TZInfoType. ob必须不 NULL.
int PyTZInfo_CheckExact(的PyObject  *ob)
如果ob的类型为PyDateTime_TZInfoType. ob,则返回true,不得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* PyTime_FromTime( int  hour,int  minute,int  second,int  usecond)
Return value: New reference.

返回datetime.time具有指定小时,分钟,秒和微秒的对象.

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

返回datetime.timedelta表示给定天数,秒数和微秒数的对象。执行标准化,以便得到的微秒和秒数位于datetime.timedeltaobjects

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参数和tzname name.

版本3.7.

用于从日期对象中提取字段的宏。参数必须是PyDateTime_Date,包括子类(如PyDateTime_DateTime)。参数不能是NULL,并且不检查类型:

int PyDateTime_GET_YEAR( PyDateTime_Date  *o)
返回年份,作为正面int.
int PyDateTime_GET_MONTH( PyDateTime_Date  *o)
返回月份,如同一个从1到12的int
int PyDateTime_GET_DAY( PyDateTime_Date  *o)
从1开始返回int通过31.

Macros从datetime对象中提取字段。参数必须是PyDateTime_DateTime的实例,包括子类。这个论点必须不是NULL,并且没有检查类型:

int PyDateTime_DATE_GET_HOUR( PyDateTime_DateTime  *o)
返回小时,作为从0到23的int
int PyDateTime_DATE_GET_MINUTE( PyDateTime_DateTime  *o)
返回分钟,作为从0到59的int.
int PyDateTime_DATE_GET_SECOND( PyDateTime_DateTime  *o)
返回第二个,作为int从0到59.
int PyDateTime_DATE_GET_MICROSECOND( PyDateTime_DateTime  *o)
返回微秒,作为从0到0的int999999.

用于从时间对象中提取字段的宏。参数必须是PyDateTime_Time的实例,包括子类。参数不能是NULL,并且不检查类型:

int PyDateTime_TIME_GET_HOUR( PyDateTime_Time  *o)
返回小时,作为从0到23的int
int PyDateTime_TIME_GET_MINUTE( PyDateTime_Time  *o)
返回分钟,作为从0到59的int.
int PyDateTime_TIME_GET_SECOND( PyDateTime_Time  *o)
返回第二个,如同一个从0到59的int.
int PyDateTime_TIME_GET_MICROSECOND( PyDateTime_Time  *o)
从0开始返回微秒,作为一个int通过999999.

Macros从时间delta对象中提取字段。参数必须是PyDateTime_Delta的实例,包括子类。参数不能是NULL,并且不检查类型:

int PyDateTime_DELTA_GET_DAYS( PyDateTime_Delta  *o)
返回从-999999999到999999999的int天数.

版本3.3.

int PyDateTime_DELTA_GET_SECONDS( PyDateTime_Delta  *o)
返回秒数,作为一个从0到86399的整数.

新版本3.3.

int PyDateTime_DELTA_GET_MICROSECONDS( PyDateTime_Delta  *o)
返回微秒数,作为从0到999999的int

在版本3.3.

Macros中为了方便实现DB API的模块:

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

创建并返回一个新的datetime.datetime对象argumenttuple适合传递给datetime.datetime.fromtimestamp().

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

创建并返回一个新的datetime.date object赋予一个适合传递给datetime.date.fromtimestamp().

评论被关闭。