The DateTimeField Class
Stay organized with collections Save and categorize content based on your preferences.
The DateTimeField
class is the field definition for datetime values. It stores a python datetime object as a field. If time zone information is included in the datetime object, it will be included in the encoded data when this is encoded/decoded.
Timezones are only encoded as minute offset from UTC. When serialized in JSON, the encoding follows the Internet Engineering Task Force RFC 3339 spec. They are not actual timezones, for example Pacific Standard Time (PST), that you could use to derive expected daylight savings behavior.
DateTimeField
is provided by the protorpc.message_types
module.
Constructor
The constructor of the DateTimeField
class is defined as follows:
- class DateTimeField (number, [required=False | repeated=False])
Initializes a DateTimeField instance.
Arguments- number
- Number of the field. Must be unique per message class.
- required=False
- Whether or not this field is required. Mutually exclusive with the
repeated
argument; do not specify repeated=True
if you use required=True
. - repeated=False
- Whether or not this field is repeated. Mutually exclusive with the
required
argument; do not specify required=True
if you use repeated=True
.
Instance Methods
DateTimeField
instances have the following methods:
- value_from_message(message)
- Convert a
DateTimeMessage
to a datetime
. Arguments- message
- The
DateTimeMessage
instance.
- value_to_message(value)
Converts a datetime
value to a DateTimeMessage
.
Arguments- value
- Value is a
datetime
instance.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-12 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-12 UTC."],[[["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`."]]],[]]