DateTime
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แสดงเวลาทั่วไป (หรือบางครั้งเป็นเวลาจริง)
ประเภทนี้สามารถแสดงเวลามาตรฐานได้ 1 ใน 2 วิธีต่อไปนี้
- เมื่อตั้งค่า utcOffset และไม่ได้ตั้งค่า timeZone: เวลาพลเรือนในวันที่ในปฏิทินซึ่งมีค่าชดเชยเวลาจาก UTC ที่เฉพาะเจาะจง
- เมื่อตั้งค่า timeZone และไม่ได้ตั้งค่า utcOffset: เวลาพลเรือนของวันในปฏิทินตามเขตเวลาหนึ่งๆ
- เมื่อไม่ได้ตั้งค่า timeZone หรือ utcOffset: เวลาพลเรือนของวันในปฏิทินตามเวลาท้องถิ่น
วันที่จะสัมพันธ์กับปฏิทินเกรโกเรียนแบบโปรเลปติก
หากปี เดือน หรือวันเป็น 0 ระบบจะถือว่า DateTime นั้นไม่มีปี เดือน หรือวันตามลำดับ
นอกจากนี้ ประเภทนี้ยังอาจใช้เพื่อแสดงเวลาจริงได้หากตั้งค่าฟิลด์วันที่และเวลาทั้งหมดและตั้งค่า time_offset
oneof ไว้ด้วย ลองใช้ข้อความ Timestamp
สำหรับเวลาจริงแทน หาก Use Case ของคุณต้องการจัดเก็บเขตเวลาของผู้ใช้ด้วย ก็สามารถดำเนินการได้ในช่องอื่น
ประเภทนี้มีความเป็นยืดหยุ่นมากกว่าที่บางแอปพลิเคชันอาจต้องการ อย่าลืมบันทึกและตรวจสอบข้อจำกัดของแอปพลิเคชัน
การแสดง 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 ได้หากอนุญาตให้ใช้วินาทีของ leap
|
nanos |
integer
ไม่บังคับ เศษส่วนของวินาทีเป็นนาโนวินาที ต้องมีค่าระหว่าง 0 ถึง 999,999,999 โดยค่าเริ่มต้นคือ 0
|
ฟิลด์สหภาพ time_offset ไม่บังคับ ระบุการชดเชยเวลา UTC หรือเขตเวลาของ DateTime โปรดเลือกอย่างรอบคอบ โดยพิจารณาว่าข้อมูลเขตเวลาอาจเปลี่ยนแปลงในอนาคต (เช่น ประเทศหนึ่งๆ แก้ไขวันที่เริ่มต้น/สิ้นสุด DST และระบบได้จัดเก็บ DateTime ในอนาคตในช่วงที่ได้รับผลกระทบไว้แล้ว) หากไม่ระบุ ระบบจะถือว่า DateTime เป็นเขตเวลาท้องถิ่น time_offset ต้องเป็นค่าใดค่าหนึ่งต่อไปนี้เท่านั้น |
utcOffset |
string (Duration format)
ความต่างเวลา UTC ต้องเป็นจำนวนเต็มวินาทีระหว่าง -18 ชั่วโมงถึง +18 ชั่วโมง เช่น ระบบจะแสดงออฟเซ็ต UTC ที่ -4:00 เป็น { seconds: -14400 } ระยะเวลาเป็นวินาทีที่มีเศษทศนิยมได้สูงสุด 9 หลัก โดยลงท้ายด้วย s เช่น "3.5s"
|
timeZone |
object (TimeZone )
เขตเวลา
|
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[],[],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. |"]]