DateTime
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Biểu thị thời gian dân sự (hoặc đôi khi là thời gian thực tế).
Loại này có thể biểu thị thời gian dân sự theo một trong những cách sau:
- Khi bạn đặt utcOffset và không đặt timeZone: thời gian dân sự vào một ngày theo lịch có độ lệch cụ thể so với giờ UTC.
- Khi bạn đặt timeZone và không đặt utcOffset: thời gian dân sự vào một ngày theo lịch trong một múi giờ cụ thể.
- Khi bạn không đặt timeZone hoặc utcOffset: thời gian dân sự vào một ngày theo lịch theo giờ địa phương.
Ngày này có liên quan đến Lịch Gregorian Proleptic.
Nếu năm, tháng hoặc ngày bằng 0, thì DateTime được coi là không có năm, tháng hoặc ngày cụ thể tương ứng.
Loại này cũng có thể được dùng để biểu thị thời gian thực tế nếu tất cả các trường ngày và giờ đều được đặt và một trong hai trường hợp của time_offset
oneof được đặt. Thay vào đó, hãy cân nhắc sử dụng thông báo Timestamp
cho thời gian thực. Nếu trường hợp sử dụng của bạn cũng muốn lưu trữ múi giờ của người dùng, thì bạn có thể thực hiện việc này trong một trường khác.
Loại này linh hoạt hơn so với một số ứng dụng có thể muốn. Hãy nhớ ghi lại và xác thực các giới hạn của ứng dụng.
Biểu diễn dưới dạng 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 .
} |
Trường |
year |
integer
Không bắt buộc. Năm của ngày. Giá trị phải từ 1 đến 9999 hoặc bằng 0 nếu chỉ định ngày giờ không có năm.
|
month |
integer
Không bắt buộc. Tháng trong năm. Giá trị phải từ 1 đến 12 hoặc bằng 0 nếu chỉ định ngày giờ không có tháng.
|
day |
integer
Không bắt buộc. Ngày trong tháng. Giá trị phải từ 1 đến 31 và có giá trị trong năm và tháng, hoặc bằng 0 nếu chỉ định ngày giờ không có ngày.
|
hours |
integer
Không bắt buộc. Giờ trong ngày theo định dạng 24 giờ. Phải nằm trong khoảng từ 0 đến 23, mặc định là 0 (nửa đêm). API có thể chọn cho phép giá trị "24:00:00" cho các tình huống như thời gian đóng cửa doanh nghiệp.
|
minutes |
integer
Không bắt buộc. Số phút trong giờ trong ngày. Phải từ 0 đến 59, mặc định là 0.
|
seconds |
integer
Không bắt buộc. Số giây trong phút. Thường phải nằm trong khoảng từ 0 đến 59, mặc định là 0. API có thể cho phép giá trị 60 nếu cho phép giây nhuận.
|
nanos |
integer
Không bắt buộc. Phân số giây tính bằng nano giây. Phải từ 0 đến 999.999.999, mặc định là 0.
|
Trường hợp hợp nhất time_offset . Không bắt buộc. Chỉ định độ lệch UTC hoặc múi giờ của DateTime. Hãy chọn cẩn thận giữa các loại dữ liệu này, vì dữ liệu múi giờ có thể thay đổi trong tương lai (ví dụ: một quốc gia sửa đổi ngày bắt đầu/kết thúc giờ mùa hè và các DateTime trong tương lai trong phạm vi bị ảnh hưởng đã được lưu trữ). Nếu bạn bỏ qua, DateTime sẽ được coi là theo giờ địa phương. time_offset chỉ có thể là một trong những loại sau: |
utcOffset |
string (Duration format)
Độ lệch giờ UTC. Phải là số nguyên giây, nằm trong khoảng từ -18 giờ đến +18 giờ. Ví dụ: độ lệch UTC là -4:00 sẽ được biểu diễn dưới dạng { seconds: -14400 }. Thời lượng tính bằng giây, có tối đa 9 chữ số thập phân, kết thúc bằng "s ". Ví dụ: "3.5s" .
|
timeZone |
object (TimeZone )
Múi giờ.
|
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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. |"]]