DateTimeField 類別
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
DateTimeField
類別是日期時間值的欄位定義,會將 Python 日期時間物件以欄位的形式儲存。如果日期時間物件內有時區資訊,則在編碼/解碼該物件時,時區資訊也會包含在編碼資料之內。
時區只會以世界標準時間的分鐘時差來編碼。在 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
。
引數
- 訊息
DateTimeMessage
例項。
- value_to_message(value)
-
將 datetime
值轉換為 DateTimeMessage
。
引數
- value
- 值為
datetime
例項。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-16 (世界標準時間)。
[[["容易理解","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-06-16 (世界標準時間)。"],[[["The `DateTimeField` class defines fields for datetime values, storing Python datetime objects and encoding timezone information as a minute offset from UTC."],["Timezone data in `DateTimeField` is encoded according to RFC 3339 when serialized in JSON, but it does not represent actual timezones like PST."],["The constructor of `DateTimeField` takes a `number` argument for field identification, along with optional `required` and `repeated` arguments that are mutually exclusive."],["`DateTimeField` instances have methods, `value_from_message` which converts a `DateTimeMessage` to a `datetime`, and `value_to_message` which converts a `datetime` to a `DateTimeMessage`."]]],[]]