Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
DateTimeField クラス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
DateTimeField
クラスは、日時型の値のフィールド定義です。これには、Python の日時オブジェクトがフィールドとして保存されます。タイムゾーン情報が日時オブジェクトに含まれている場合、その情報はエンコード / デコード時にエンコード データに含まれます。
タイムゾーンは、UTC からの分単位のオフセットとしてのみエンコードされます。JSON でシリアル化する場合は、インターネット技術特別調査委員会の RFC 3339 仕様に従ってエンコードされます。これは、想定される夏時間の動作を得るために使用できる実際のタイムゾーン(太平洋標準時(PST)など)ではありません。
DateTimeField
は、protorpc.message_types
モジュールによって提供されます。
コンストラクタ
DateTimeField
クラスのコンストラクタは、次のように定義されます。
- class
DateTimeField
(number,
[required=False
| repeated=False])
-
DateTimeField インスタンスを初期化します。
引数
- number
- フィールドの番号。メッセージ クラスごとに一意でなければなりません。
- required=False
- このフィールドが必須かどうかを指定します。
repeated
引数と同時に指定することはできません。required=True
を使用する場合、repeated=True
は指定しないでください。
- repeated=False
- このフィールドが反復フィールドかどうかを指定します。
required
引数と同時に指定することはできません。repeated=True
を使用する場合、required=True
は指定しないでください。
インスタンス メソッド
DateTimeField
インスタンスには、次のメソッドがあります。
- value_from_message(message)
DateTimeMessage
を datetime
に変換します。引数- message
DateTimeMessage
インスタンス。
- value_to_message(value)
-
datetime
値を DateTimeMessage
に変換します。
引数
- value
- value は
datetime
インスタンスです。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[[["\u003cp\u003eThe \u003ccode\u003eDateTimeField\u003c/code\u003e class defines fields for datetime values, storing Python datetime objects and encoding timezone information as a minute offset from UTC.\u003c/p\u003e\n"],["\u003cp\u003eTimezone data in \u003ccode\u003eDateTimeField\u003c/code\u003e is encoded according to RFC 3339 when serialized in JSON, but it does not represent actual timezones like PST.\u003c/p\u003e\n"],["\u003cp\u003eThe constructor of \u003ccode\u003eDateTimeField\u003c/code\u003e takes a \u003ccode\u003enumber\u003c/code\u003e argument for field identification, along with optional \u003ccode\u003erequired\u003c/code\u003e and \u003ccode\u003erepeated\u003c/code\u003e arguments that are mutually exclusive.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDateTimeField\u003c/code\u003e instances have methods, \u003ccode\u003evalue_from_message\u003c/code\u003e which converts a \u003ccode\u003eDateTimeMessage\u003c/code\u003e to a \u003ccode\u003edatetime\u003c/code\u003e, and \u003ccode\u003evalue_to_message\u003c/code\u003e which converts a \u003ccode\u003edatetime\u003c/code\u003e to a \u003ccode\u003eDateTimeMessage\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# The DateTimeField Class\n\nThe `DateTimeField` class is the field definition for datetime\nvalues. It stores a python datetime object as a field. If time zone information\nis included in the datetime object, it will be included in the encoded data when\nthis is encoded/decoded.\n\nTimezones are only encoded as minute offset from UTC. When\nserialized in JSON, the encoding follows the Internet Engineering Task Force\n[RFC 3339](http://www.ietf.org/rfc/rfc3339.txt) spec. They are\nnot actual timezones, for example Pacific Standard Time (PST), that you could\nuse to derive expected daylight savings behavior.\n\n`DateTimeField` is provided by the `protorpc.message_types`\nmodule.\n\nConstructor\n-----------\n\nThe constructor of the `DateTimeField` class is defined as\nfollows:\n\nclass\nDateTimeField\n(number,\n\\[required=False\n\\| repeated=False\\])\n\n: Initializes a DateTimeField instance.\n\n **Arguments**\n\n number\n : Number of the field. Must be unique per message class.\n\n required=False\n : Whether or not this field is required. Mutually exclusive with the\n `repeated` argument; do not specify\n `repeated=True` if you use `required=True`.\n\n repeated=False\n : Whether or not this field is repeated. Mutually exclusive with the\n `required` argument; do not specify\n `required=True` if you use `repeated=True`.\n\nInstance Methods\n----------------\n\n`DateTimeField` instances have the following methods:\n\nvalue_from_message(message)\n: Convert a `DateTimeMessage` to a `datetime`.\n **Arguments**\n\n message\n : The `DateTimeMessage` instance.\n\nvalue_to_message(value)\n\n: Converts a `datetime` value to a\n `DateTimeMessage`.\n\n **Arguments**\n\n value\n : Value is a `datetime` instance."]]