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.
-
PyDateTime_IMPORT()¶
Import the datetime C API.
On success, populate the
PyDateTimeAPIpointer. On failure, setPyDateTimeAPItoNULLand set an exception. The caller must check if an error occurred viaPyErr_Occurred():PyDateTime_IMPORT; if (PyErr_Occurred()) { /* cleanup */ }
警告
This is not compatible with subinterpreters.
-
type PyDateTime_CAPI¶
Structure containing the fields for the datetime C API.
The fields of this structure are private and subject to change.
Do not use this directly; prefer
PyDateTime_*APIs instead.
-
PyDateTime_CAPI *PyDateTimeAPI¶
Dynamically allocated object containing the datetime C API.
This variable is only available once
PyDateTime_IMPORTsucceeds.
-
PyTypeObject PyDateTime_DateType¶
この
PyTypeObjectのインスタンスは Python の date 型を表します; Python レイヤにおけるdatetime.dateと同じオブジェクトです。
-
PyTypeObject PyDateTime_DateTimeType¶
この
PyTypeObjectのインスタンスは Python の datetime 型を表現します; Python レイヤにおけるdatetime.datetimeと同じオブジェクトです。
-
PyTypeObject PyDateTime_TimeType¶
この
PyTypeObjectのインスタンスは Python の time 型を表します; Python レイヤにおけるdatetime.timeと同じオブジェクトです。
-
PyTypeObject PyDateTime_DeltaType¶
This instance of
PyTypeObjectrepresents the Python type for the difference between two datetime values; it is the same object asdatetime.timedeltain the Python layer.
-
PyTypeObject PyDateTime_TZInfoType¶
この
PyTypeObjectのインスタンスは Python の タイムゾーン情報型を表します; Python レイヤにおけるdatetime.tzinfoと同じオブジェクトです。
UTCシングルトンにアクセスするためのマクロ:
-
PyObject *PyDateTime_TimeZone_UTC¶
UTCタイムゾーンに相当するシングルトンを返します。これは
datetime.timezone.utcと同じオブジェクトです。Added in version 3.7.
型チェックマクロ:
-
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であってはなりません。この関数は常に成功します。
-
int 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 はNULLであってはなりません。この関数は常に成功します。
以下はオブジェクトを作成するためのマクロです:
-
PyObject *PyDate_FromDate(int year, int month, int day)¶
- 戻り値: 新しい参照。
指定した年、月、日の
datetime.dateオブジェクトを返します。
-
PyObject *PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)¶
- 戻り値: 新しい参照。
指定した年、月、日、時、分、秒、マイクロ秒の
datetime.datetimeオブジェクトを返します。
-
PyObject *PyDateTime_FromDateAndTimeAndFold(int year, int month, int day, int hour, int minute, int second, int usecond, int fold)¶
- 戻り値: 新しい参照。
指定された年、月、日、時、分、秒、マイクロ秒、fold の
datetime.datetimeオブジェクトを返します。Added in version 3.6.
-
PyObject *PyTime_FromTime(int hour, int minute, int second, int usecond)¶
- 戻り値: 新しい参照。
指定された時、分、秒、マイクロ秒の
datetime.timeオブジェクトを返します。
-
PyObject *PyTime_FromTimeAndFold(int hour, int minute, int second, int usecond, int fold)¶
- 戻り値: 新しい参照。
指定された時、分、秒、マイクロ秒、fold の
datetime.timeオブジェクトを返します。Added in version 3.6.
-
PyObject *PyDelta_FromDSU(int days, int seconds, int useconds)¶
- 戻り値: 新しい参照。
指定された日、秒、マイクロ秒の
datetime.timedeltaオブジェクトを返します。マイクロ秒と秒がdatetime.timedeltaオブジェクトで定義されている範囲に入るように正規化を行います。
-
PyObject *PyTimeZone_FromOffset(PyObject *offset)¶
- 戻り値: 新しい参照。
offset 引数で指定した固定オフセットを持つ、名前のない
datetime.timezoneオブジェクトを返します。Added in version 3.7.
-
PyObject *PyTimeZone_FromOffsetAndName(PyObject *offset, PyObject *name)¶
- 戻り値: 新しい参照。
offset*引数で指定した固定のオフセットと、*name のタイムゾーン名を持つ
datetime.timezoneオブジェクトを返します。Added in version 3.7.
以下のマクロは date オブジェクトからフィールド値を取り出すためのものです。引数は 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 の間の整数で返します。
以下のマクロは datetime オブジェクトからフィールド値を取り出すためのものです。引数は 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 の間の整数で返します。
-
int PyDateTime_DATE_GET_FOLD(PyDateTime_DateTime *o)¶
フォールド(訳注: サマータイムによる時間のずれのこと)を 0 から 1 までの整数で返します。
Added in version 3.6.
-
PyObject *PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)¶
Return the tzinfo (which may be
None).Added in version 3.10.
以下のマクロは time オブジェクトからフィールド値を取り出すためのものです。引数は 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 の間の整数で返します。
-
int PyDateTime_TIME_GET_FOLD(PyDateTime_Time *o)¶
フォールド(訳注: サマータイムによる時間のずれのこと)を 0 から 1 までの整数で返します。
Added in version 3.6.
-
PyObject *PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)¶
Return the tzinfo (which may be
None).Added in version 3.10.
以下のマクロは time delta オブジェクトからフィールド値をとりだすためのものです。引数は PyDateTime_Delta かそのサブクラスのインスタンスでなければなりません。引数を NULL にしてはならず、型チェックは行いません:
-
int PyDateTime_DELTA_GET_DAYS(PyDateTime_Delta *o)¶
日数を -999999999 から 999999999 の間の整数で返します。
Added in version 3.3.
-
int PyDateTime_DELTA_GET_SECONDS(PyDateTime_Delta *o)¶
秒数を 0 から 86399 の間の整数で返します。
Added in version 3.3.
-
int PyDateTime_DELTA_GET_MICROSECONDS(PyDateTime_Delta *o)¶
マイクロ秒を 0 から 999999 の間の整数で返します。
Added in version 3.3.
以下のマクロは DB API を実装する上での便宜用です:
-
PyObject *PyDateTime_FromTimestamp(PyObject *args)¶
- 戻り値: 新しい参照。
Create and return a new
datetime.datetimeobject given an argument tuple suitable for passing todatetime.datetime.fromtimestamp().
-
PyObject *PyDate_FromTimestamp(PyObject *args)¶
- 戻り値: 新しい参照。
Create and return a new
datetime.dateobject given an argument tuple suitable for passing todatetime.date.fromtimestamp().
Internal data¶
The following symbols are exposed by the C API but should be considered internal-only.
-
PyDateTime_CAPSULE_NAME¶
Name of the datetime capsule to pass to
PyCapsule_Import().Internal usage only. Use
PyDateTime_IMPORTinstead.