DateTime
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
代表民用時間 (或偶爾實際時間)。
此型別能以幾種可能方式表示民用時間:
- 設定 utcOffset 且 timeZone 未設定時:日曆日期的民用時間,且特定與世界標準時間的偏移值。
- 設定 timeZone 且未設定 utcOffset 時:特定時區在日曆日期中的民用時間。
- 如果未指定 timeZone 或 utcOffset 時:一個日曆天以當地時間為準的民用時間。
日期以{0}公曆為主。
如果年、月或日為 0,則 DateTime 會視為不分別特定年、月或日。
如果設定了所有日期和時間欄位,且已設定 time_offset
其中一個欄位,這個類型也可以代表實體時間。建議改用 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 時區。請謹慎選擇時區,因為時區資料日後可能會改變 (例如:國家/地區修改了 DST 的開始/結束日期,以及受影響時間範圍內的未來日期時間)。如果省略,DateTime 會視為當地時間。time_offset 只能是下列其中一項: |
utcOffset |
string (Duration format)
世界標準時間偏移。必須為整數,介於 -18 小時至 +18 小時之間。舉例來說,世界標準時間偏移 -4:00 應以 { seconds: -14400 } 表示。 持續時間以秒為單位,最多 9 個小數位數,結尾為「s 」。範例:"3.5s" 。
|
timeZone |
object (TimeZone )
時區。
|
TimeZone
JSON 表示法 |
{
"id": string,
"version": string
} |
欄位 |
id |
string
IANA 時區資料庫時區,例如「America/New_York」。
|
version |
string
選用設定。IANA 時區資料庫版本號碼,例如「2019a」。
|
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-08-23 (世界標準時間)。
[null,null,["上次更新時間:2024-08-23 (世界標準時間)。"],[[["\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\". |"]]