DateTime オブジェクト¶
Various date and time objects are supplied by the datetime
module.
Before using any of these functions, the header file datetime.h
must be
included in your source (note that this is not included by Python.h
),
and the macro PyDateTime_IMPORT
must be invoked, usually as part of
the module initialisation function. The macro puts a pointer to a C structure
into a static variable, PyDateTimeAPI
, that is used by the following
macros.
-
type PyDateTime_Delta¶
This subtype of
PyObject
represents the difference between two datetime values.
-
PyTypeObject PyDateTime_DateType¶
This instance of
PyTypeObject
represents the Python date type; it is the same object asdatetime.date
in the Python layer.
-
PyTypeObject PyDateTime_DateTimeType¶
This instance of
PyTypeObject
represents the Python datetime type; it is the same object asdatetime.datetime
in the Python layer.
-
PyTypeObject PyDateTime_TimeType¶
This instance of
PyTypeObject
represents the Python time type; it is the same object asdatetime.time
in the Python layer.
-
PyTypeObject PyDateTime_DeltaType¶
This instance of
PyTypeObject
represents Python type for the difference between two datetime values; it is the same object asdatetime.timedelta
in the Python layer.
-
PyTypeObject PyDateTime_TZInfoType¶
This instance of
PyTypeObject
represents the Python time zone info type; it is the same object asdatetime.tzinfo
in the Python layer.
UTCシングルトンにアクセスするためのマクロ:
-
PyObject *PyDateTime_TimeZone_UTC¶
UTCタイムゾーンに相当するシングルトンを返します。 これは
datetime.timezon.utc
と同じオブジェクトです。バージョン 3.7 で追加.
型チェックマクロ:
-
int PyDate_Check(PyObject *ob)¶
Return true if ob is of type
PyDateTime_DateType
or a subtype ofPyDateTime_DateType
. ob must not beNULL
. This function always succeeds.
-
int PyDate_CheckExact(PyObject *ob)¶
ob が
PyDateTime_DateType
の場合に真を返します。 ob はNULL
であってはなりません。この関数は常に成功します。
-
int PyDateTime_Check(PyObject *ob)¶
Return true if ob is of type
PyDateTime_DateTimeType
or a subtype ofPyDateTime_DateTimeType
. ob must not beNULL
. This function always succeeds.
-
int PyDateTime_CheckExact(PyObject *ob)¶
ob が
PyDateTime_DateTimeType
の場合に真を返します。 ob はNULL
であってはなりません。この関数は常に成功します。
-
int PyTime_Check(PyObject *ob)¶
Return true if ob is of type
PyDateTime_TimeType
or a subtype ofPyDateTime_TimeType
. ob must not beNULL
. This function always succeeds.
-
int PyTime_CheckExact(PyObject *ob)¶
ob が
PyDateTime_TimeType
の場合に真を返します。 ob はNULL
であってはなりません。この関数は常に成功します。
-
int PyDelta_Check(PyObject *ob)¶
Return true if ob is of type
PyDateTime_DeltaType
or a subtype ofPyDateTime_DeltaType
. ob must not beNULL
. This function always succeeds.
-
int PyDelta_CheckExact(PyObject *ob)¶
ob が
PyDateTime_DeltaType
の場合に真を返します。 ob はNULL
であってはなりません。この関数は常に成功します。
-
int PyTZInfo_Check(PyObject *ob)¶
Return true if ob is of type
PyDateTime_TZInfoType
or a subtype ofPyDateTime_TZInfoType
. ob must not beNULL
. This function always succeeds.
-
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.
指定された年、月、日、時、分、秒、マイクロ秒、fold の
datetime.datetime
オブジェクトを返します。バージョン 3.6 で追加.
-
PyObject *PyTime_FromTime(int hour, int minute, int second, int usecond)¶
- Return value: New reference.
指定された時、分、秒、マイクロ秒の
datetime.time
オブジェクトを返します。
-
PyObject *PyTime_FromTimeAndFold(int hour, int minute, int second, int usecond, int fold)¶
- Return value: New reference.
指定された時、分、秒、マイクロ秒、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(PyObject *offset)¶
- Return value: New reference.
offset 引数で指定した固定オフセットを持つ、名前のない
datetime.timezone
オブジェクトを返します。バージョン 3.7 で追加.
-
PyObject *PyTimeZone_FromOffsetAndName(PyObject *offset, PyObject *name)¶
- Return value: New reference.
offset*引数で指定した固定のオフセットと、*name のタイムゾーン名を持つ
datetime.timezone
オブジェクトを返します。バージョン 3.7 で追加.
Macros to extract fields from date objects. The argument must be an instance of
PyDateTime_Date
, including subclasses (such as
PyDateTime_DateTime
). The argument must not be NULL
, and the type is
not checked:
-
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 の間の整数で返します。
Macros to extract fields from datetime objects. The argument must be an
instance of PyDateTime_DateTime
, including subclasses. The argument
must not be NULL
, and the type is not checked:
-
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 の間の整数で返します。
-
int PyDateTime_DATE_GET_FOLD(PyDateTime_DateTime *o)¶
フォールド(訳注: サマータイムによる時間のずれのこと)を 0 から 1 までの整数で返します。
バージョン 3.6 で追加.
-
PyObject *PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)¶
Return the tzinfo (which may be
None
).バージョン 3.10 で追加.
Macros to extract fields from time objects. The argument must be an instance of
PyDateTime_Time
, including subclasses. The argument must not be NULL
,
and the type is not checked:
-
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 の間の整数で返します。
-
int PyDateTime_TIME_GET_FOLD(PyDateTime_Time *o)¶
フォールド(訳注: サマータイムによる時間のずれのこと)を 0 から 1 までの整数で返します。
バージョン 3.6 で追加.
-
PyObject *PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)¶
Return the tzinfo (which may be
None
).バージョン 3.10 で追加.
Macros to extract fields from time delta objects. The argument must be an
instance of PyDateTime_Delta
, including subclasses. The argument must
not be NULL
, and the type is not checked:
-
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.
dateitme.datetime.fromtimestamp()
に渡すのに適した引数タプルから新たなdatetime.datetime
オブジェクトを生成して返します。
-
PyObject *PyDate_FromTimestamp(PyObject *args)¶
- Return value: New reference.
dateitme.date.fromtimestamp()
に渡すのに適した引数タプルから新たなdatetime.date
オブジェクトを生成して返します。