DateTime
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Representa el tiempo civil (o, en ocasiones, el tiempo físico).
Este tipo puede representar una hora civil de una de las siguientes maneras:
- Cuando se configura utcOffset y no se establece timeZone: una hora civil en un día calendario con una diferencia particular con respecto a UTC.
- Cuando se establece timeZone y utcOffset no se establezca: una hora civil de un día calendario en una zona horaria específica.
- Si no se establecen timeZone ni utcOffset: una hora civil en un día calendario en la hora local
La fecha está relacionada con el calendario gregoriano proléptico.
Si el valor de año, mes o día es 0, se considera que DateTime no tiene un año, mes o día específico respectivamente.
Este tipo también se puede usar para representar una hora física si se configuran todos los campos de fecha y hora y se establece cualquiera de las sentencias case de time_offset
. En su lugar, puedes usar el mensaje Timestamp
para pasar tiempo físico. Si en tu caso de uso también deseas almacenar la zona horaria del usuario, puedes hacerlo en otro campo.
Este tipo es más flexible de lo que podrían querer algunas aplicaciones. Asegúrate de documentar y validar las limitaciones de tu aplicación.
Representación JSON |
{
"year": integer,
"month": integer,
"day": integer,
"hours": integer,
"minutes": integer,
"seconds": integer,
"nanos": integer,
// Union field time_offset can be only one of the following:
"utcOffset": string,
"timeZone": {
object (TimeZone )
}
// End of list of possible types for union field time_offset .
} |
Campos |
year |
integer
Opcional. Año de la fecha. Debe encontrarse entre 1 y 9999, o 0 si se especifica una fecha y hora sin año.
|
month |
integer
Opcional. Mes del año. Debe encontrarse entre 1 y 12, o 0 si se especifica una fecha y hora sin mes.
|
day |
integer
Opcional. Día del mes. Debe encontrarse entre 1 y 31 y ser válido para el año y el mes, o 0 si se especifica una fecha y hora sin un día.
|
hours |
integer
Opcional. Horas del día en formato de 24 horas. Debe ser de 0 a 23; el valor predeterminado es 0 (medianoche). Una API puede permitir el valor “24:00:00” para casos como el horario de cierre de empresas.
|
minutes |
integer
Opcional. Minutos de horas del día. Debe ser un valor entre 0 y 59; el valor predeterminado es 0.
|
seconds |
integer
Opcional. Segundos de minutos de la hora. Por lo general, debe estar entre 0 y 59; el valor predeterminado es 0. Una API puede permitir el valor 60 si permite segundos bisiestos.
|
nanos |
integer
Opcional. Fracciones de segundos en nanosegundos. Debe ser un valor entre 0 y 999,999,999; el valor predeterminado es 0.
|
Campo de unión time_offset . Opcional. Especifica el desplazamiento de UTC o la zona horaria de DateTime. Elige cuidadosamente entre ellas. Ten en cuenta que los datos de la zona horaria pueden cambiar en el futuro (por ejemplo, un país modifica las fechas de inicio y finalización del DST, y ya se almacenaron las fechas y horas futuras en el rango afectado). Si se omite, se considera que DateTime está en la hora local. Las direcciones (time_offset ) solo pueden ser una de las siguientes opciones: |
utcOffset |
string (Duration format)
Compensación de UTC. Deben ser segundos enteros, entre -18 horas y +18 horas. Por ejemplo, una compensación UTC de -4:00 se representaría como { segundos: -14400 }. Una duración en segundos con hasta nueve dígitos decimales, que terminan en “s ”. Ejemplo: "3.5s" .
|
timeZone |
object (TimeZone )
Zona horaria.
|
TimeZone
Representación JSON |
{
"id": string,
"version": string
} |
Campos |
id |
string
Zona horaria de la base de datos de zonas horarias de IANA, p. ej., “America/New_York”.
|
version |
string
Opcional. Número de versión de la base de datos de zonas horarias de IANA, p. ej., “2019a”.
|
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2024-08-23 (UTC)
[null,null,["Última actualización: 2024-08-23 (UTC)"],[[["\u003cp\u003eDateTime represents civil time, relative to the Proleptic Gregorian Calendar, and can also be used to represent physical time.\u003c/p\u003e\n"],["\u003cp\u003eIt can specify time with UTC offset, a specific time zone, or in local time if both are unset.\u003c/p\u003e\n"],["\u003cp\u003eDateTime allows flexibility in specifying date and time, including omitting year, month, or day.\u003c/p\u003e\n"],["\u003cp\u003eIt's recommended to use \u003ccode\u003eTimestamp\u003c/code\u003e message for physical time and store user's timezone in a separate field if needed.\u003c/p\u003e\n"],["\u003cp\u003eApplications should carefully document and validate limitations due to the flexible nature of DateTime.\u003c/p\u003e\n"]]],["This content defines a `DateTime` type, representing civil or physical time. It can specify time via UTC offset, a time zone, or local time. The date is based on the Proleptic Gregorian Calendar, and year, month, or day values can be zero if unspecified. `DateTime` can store year, month, day, hour, minutes, seconds, and nanoseconds. The `time_offset` field allows setting either a UTC offset or a time zone, supporting flexibility. TimeZone contains id and version fields.\n"],null,["# DateTime\n\nRepresents civil time (or occasionally physical time).\n\nThis type can represent a civil time in one of a few possible ways:\n\n- When utcOffset is set and timeZone is unset: a civil time on a calendar day with a particular offset from UTC.\n- When timeZone is set and utcOffset is unset: a civil time on a calendar day in a particular time zone.\n- When neither timeZone nor utcOffset is set: a civil time on a calendar day in local time.\n\nThe date is relative to the Proleptic Gregorian Calendar.\n\nIf year, month, or day are 0, the DateTime is considered not to have a specific year, month, or day respectively.\n\nThis type may also be used to represent a physical time if all the date and time fields are set and either case of the `time_offset` oneof is set. Consider using `Timestamp` message for physical time instead. If your use case also would like to store the user's timezone, that can be done in another field.\n\nThis type is more flexible than some applications may want. Make sure to document and validate your application's limitations.\n\n| JSON representation |\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"year\": integer, \"month\": integer, \"day\": integer, \"hours\": integer, \"minutes\": integer, \"seconds\": integer, \"nanos\": integer, // Union field `time_offset` can be only one of the following: \"utcOffset\": string, \"timeZone\": { object (/optimization/service/reference/rest/v1/DateTime#TimeZone) } // End of list of possible types for union field `time_offset`. } ``` |\n\n| Fields ||\n|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `year` | `integer` Optional. Year of date. Must be from 1 to 9999, or 0 if specifying a datetime without a year. |\n| `month` | `integer` Optional. Month of year. Must be from 1 to 12, or 0 if specifying a datetime without a month. |\n| `day` | `integer` Optional. Day of month. Must be from 1 to 31 and valid for the year and month, or 0 if specifying a datetime without a day. |\n| `hours` | `integer` Optional. Hours of day in 24 hour format. Should be from 0 to 23, defaults to 0 (midnight). An API may choose to allow the value \"24:00:00\" for scenarios like business closing time. |\n| `minutes` | `integer` Optional. Minutes of hour of day. Must be from 0 to 59, defaults to 0. |\n| `seconds` | `integer` Optional. Seconds of minutes of the time. Must normally be from 0 to 59, defaults to 0. An API may allow the value 60 if it allows leap-seconds. |\n| `nanos` | `integer` Optional. Fractions of seconds in nanoseconds. Must be from 0 to 999,999,999, defaults to 0. |\n| Union field `time_offset`. Optional. Specifies either the UTC offset or the time zone of the DateTime. Choose carefully between them, considering that time zone data may change in the future (for example, a country modifies their DST start/end dates, and future DateTimes in the affected range had already been stored). If omitted, the DateTime is considered to be in local time. `time_offset` can be only one of the following: ||\n| `utc``Offset` | `string (`[Duration](https://protobuf.dev/reference/protobuf/google.protobuf/#duration)` format)` UTC offset. Must be whole seconds, between -18 hours and +18 hours. For example, a UTC offset of -4:00 would be represented as { seconds: -14400 }. A duration in seconds with up to nine fractional digits, ending with '`s`'. Example: `\"3.5s\"`. |\n| `time``Zone` | `object (`[TimeZone](/optimization/service/reference/rest/v1/DateTime#TimeZone)`)` Time zone. |\n\nTimeZone\n--------\n\nRepresents a time zone from the [IANA Time Zone Database](https://www.iana.org/time-zones).\n\n| JSON representation |\n|---------------------------------------------|\n| ``` { \"id\": string, \"version\": string } ``` |\n\n| Fields ||\n|-----------|---------------------------------------------------------------------------------|\n| `id` | `string` IANA Time Zone Database time zone. For example \"America/New_York\". |\n| `version` | `string` Optional. IANA Time Zone Database version number. For example \"2019a\". |"]]