Package google.protobuf
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
مدت زمان
مدت زمان نشان دهنده یک بازه زمانی مشخص و با طول ثابت است که به صورت شمارش ثانیه و کسری از ثانیه در وضوح نانوثانیه نمایش داده می شود. مستقل از هر تقویم و مفاهیمی مانند "روز" یا "ماه" است. از آنجایی که تفاوت بین دو مقدار Timestamp یک مدت زمان است و می توان آن را از یک Timestamp اضافه یا کم کرد، با Timestamp مرتبط است. برد تقریباً +10000 سال است.
مثال 1: مدت زمان را از دو مُهر زمانی در شبه کد محاسبه کنید.
Timestamp start = ...;
Timestamp end = ...;
Duration duration = ...;
duration.seconds = end.seconds - start.seconds;
duration.nanos = end.nanos - start.nanos;
if (duration.seconds < 0 && duration.nanos > 0) {
duration.seconds += 1;
duration.nanos -= 1000000000;
} else if (duration.seconds > 0 && duration.nanos < 0) {
duration.seconds -= 1;
duration.nanos += 1000000000;
}
مثال 2: مهر زمانی را از Timestamp + Duration در شبه کد محاسبه کنید.
Timestamp start = ...;
Duration duration = ...;
Timestamp end = ...;
end.seconds = start.seconds + duration.seconds;
end.nanos = start.nanos + duration.nanos;
if (end.nanos < 0) {
end.seconds -= 1;
end.nanos += 1000000000;
} else if (end.nanos >= 1000000000) {
end.seconds += 1;
end.nanos -= 1000000000;
}
نام زمینه | تایپ کنید | شرح |
---|
seconds | int64 | ثانیه های امضا شده از بازه زمانی. باید از -315,576,000,000 تا +315,576,000,000 باشد. |
nanos | int32 | علامت کسری از ثانیه در وضوح نانوثانیه از بازه زمانی. مدت زمان کمتر از یک ثانیه با یک میدان 0 seconds و یک میدان nanos مثبت یا منفی نشان داده می شود. برای مدت زمان یک ثانیه یا بیشتر، یک مقدار غیر صفر برای فیلد nanos باید همان علامت فیلد seconds باشد. باید از 999,999,999- تا 999,999,999+ باشد. |
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2024-06-26 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2024-06-26 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003e\u003ccode\u003eDuration\u003c/code\u003e represents a time span with seconds and nanoseconds, independent of calendar concepts.\u003c/p\u003e\n"],["\u003cp\u003eIt can be calculated by finding the difference between two \u003ccode\u003eTimestamp\u003c/code\u003e values.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDuration\u003c/code\u003e can be added to or subtracted from a \u003ccode\u003eTimestamp\u003c/code\u003e to compute a new \u003ccode\u003eTimestamp\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eValid \u003ccode\u003eDuration\u003c/code\u003e values range from approximately -10,000 years to +10,000 years.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eseconds\u003c/code\u003e field represents the seconds and \u003ccode\u003enanos\u003c/code\u003e field represents the nanoseconds of the duration.\u003c/p\u003e\n"]]],[],null,["# Package google.protobuf\n\nIndex\n-----\n\n- [Duration](/digital-asset-links/reference/rpc/google.protobuf#google.protobuf.Duration) (message)\n\nDuration\n--------\n\nA Duration represents a signed, fixed-length span of time represented as a count of seconds and fractions of seconds at nanosecond resolution. It is independent of any calendar and concepts like \"day\" or \"month\". It is related to Timestamp in that the difference between two Timestamp values is a Duration and it can be added or subtracted from a Timestamp. Range is approximately +-10,000 years.\n\nExample 1: Compute Duration from two Timestamps in pseudo code. \n\n Timestamp start = ...;\n Timestamp end = ...;\n Duration duration = ...;\n\n duration.seconds = end.seconds - start.seconds;\n duration.nanos = end.nanos - start.nanos;\n\n if (duration.seconds \u003c 0 && duration.nanos \u003e 0) {\n duration.seconds += 1;\n duration.nanos -= 1000000000;\n } else if (duration.seconds \u003e 0 && duration.nanos \u003c 0) {\n duration.seconds -= 1;\n duration.nanos += 1000000000;\n }\n\nExample 2: Compute Timestamp from Timestamp + Duration in pseudo code. \n\n Timestamp start = ...;\n Duration duration = ...;\n Timestamp end = ...;\n\n end.seconds = start.seconds + duration.seconds;\n end.nanos = start.nanos + duration.nanos;\n\n if (end.nanos \u003c 0) {\n end.seconds -= 1;\n end.nanos += 1000000000;\n } else if (end.nanos \u003e= 1000000000) {\n end.seconds += 1;\n end.nanos -= 1000000000;\n }\n\n| Field name | Type | Description |\n|------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `seconds` | `int64` | Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. |\n| `nanos` | `int32` | Signed fractions of a second at nanosecond resolution of the span of time. Durations less than one second are represented with a 0 `seconds` field and a positive or negative `nanos` field. For durations of one second or more, a non-zero value for the `nanos` field must be of the same sign as the `seconds` field. Must be from -999,999,999 to +999,999,999 inclusive. |"]]