DateTimeField 类
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
DateTimeField
类是日期时间值的字段定义。它将 python datetime 对象存储为字段。如果时区信息包含在时间日期对象中,对其编码/解码后,该信息将包含在编码数据中。
时区仅编码为世界协调时间 (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
。
参数
- 消息
DateTimeMessage
实例。
- value_to_message(value)
-
将 datetime
值转换为 DateTimeMessage
。
参数
- value
- 值是一个
datetime
实例。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-09。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-04-09。"],[[["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`."]]],[]]