Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.

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.


The constructor of the DateTimeField class is defined as follows:

class  DateTimeField (number, [required=False | repeated=False])

Initializes a DateTimeField instance.

Number of the field. Must be unique per message class.
Whether or not this field is required. Mutually exclusive with the repeated argument; do not specify repeated=True if you use required=True.
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:

Convert a DateTimeMessage to a datetime. Arguments
The DateTimeMessage instance.

Converts a datetime value to a DateTimeMessage.

Value is a datetime instance.