DateTime
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
代表民用時間 (或偶爾的實際時間)。
這個類型可透過以下幾種方式表示公元時間:
- 當 utcOffset 已設定且 timeZone 未設定時:日曆日期的民用時間,與世界標準時間有特定偏移。
- 當 timeZone 已設定,但 utcOffset 未設定時:特定時區中日曆日期的民用時間。
- 如果未設定 timeZone 或 utcOffset:以當地時間表示的曆法日民用時間。
日期以西曆為主。
如果年、月或日為 0,系統會認為 DateTime 分別沒有特定年、月或日。
如果已設定所有日期和時間欄位,且已設定 time_offset
oneof 的任一情況,則也可使用此類型來表示實際時間。建議您改用 Timestamp
訊息來表示實際時間。如果您的用途也想儲存使用者的時區,可以使用其他欄位。
這類型比某些應用程式所需的彈性更高。請務必記錄並驗證應用程式的限制。
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 .
} |
欄位 |
year |
integer
選用設定。日期的年份。必須為 1 到 9999;如要指定不含年份的日期時間,請輸入 0。
|
month |
integer
選用設定。月份。必須為 1 到 12;如要指定不含月份的日期時間,請輸入 0。
|
day |
integer
選用設定。當月第幾日。必須為 1 到 31,並屬於有效的年和月;如果只指定日期時間,請輸入 0。
|
hours |
integer
選用設定。一天中的小時,採用 24 小時制。值應介於 0 到 23 之間,預設值為 0 (午夜)。API 可選擇允許使用「24:00:00」這類的值來表示營業打烊時間等情況。
|
minutes |
integer
選用設定。一天中,每小時內的分鐘。值必須介於 0 到 59 之間,預設值為 0。
|
seconds |
integer
選用設定。在當下時間中,該分鐘的秒數。值必須介於 0 到 59 之間,預設為 0。如果 API 允許閏秒,則可允許值為 60。
|
nanos |
integer
選用設定。秒數的小數,以奈秒為單位。值必須介於 0 到 999,999,999 之間,預設值為 0。
|
聯集欄位 time_offset 。選用設定。指定 DateTime 的 UTC 偏移或時區。請謹慎選擇,因為時區資料日後可能會變更 (例如,某個國家/地區修改夏令時間開始/結束日期,而受影響範圍內的未來日期/時間已儲存)。如果省略,系統會將 DateTime 視為當地時間。time_offset 只能是下列其中一項: |
utcOffset |
string (Duration format)
世界標準時間時差。必須是整數秒,介於 -18 小時和 +18 小時之間。舉例來說,如果 UTC 偏移值為 -4:00,則會以 { seconds: -14400 } 表示。 以秒為單位的時間長度,最多可有 9 個小數位數,結尾為「s 」,例如:"3.5s" 。
|
timeZone |
object (TimeZone )
時區。
|
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# DateTime\n\n- [JSON representation](#SCHEMA_REPRESENTATION)\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 (/maps/documentation/weather/reference/rest/v1/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](/maps/documentation/weather/reference/rest/v1/TimeZone)`)` Time zone. |"]]