Returns aComparatorforTimestampswhich sorts in increasing
chronological order. Nulls and invalidTimestampsare not allowed (see#isValid). The returned comparator is serializable.
Returns true if the givenTimestampis valid. Thesecondsvalue must be in the
range [-62,135,596,800, +253,402,300,799] (i.e., between 0001-01-01T00:00:00Z and
9999-12-31T23:59:59Z). Thenanosvalue must be in the range [0, +999,999,999].
Note:Negative second values with fractional seconds must still have non-negative
nanos values that count forward in time.
Returns true if the given number of seconds and nanos is a validTimestamp. Thesecondsvalue must be in the range [-62,135,596,800, +253,402,300,799] (i.e., between
0001-01-01T00:00:00Z and 9999-12-31T23:59:59Z). Thenanosvalue must be in the range
[0, +999,999,999].
Note:Negative second values with fractional seconds must still have non-negative
nanos values that count forward in time.
Parse from RFC 3339 date string to Timestamp. This method accepts all outputs of#toString(Timestamp)and it also accepts any fractional digits (or none) and any offset as
long as they fit into nano-seconds precision.
Example of accepted format: "1972-01-01T10:00:20.021-05:00"
Convert a Timestamp to the number of microseconds elapsed from the epoch.
The result will be rounded down to the nearest microsecond. E.g., if the timestamp
represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 microsecond.
Convert a Timestamp to the number of milliseconds elapsed from the epoch.
The result will be rounded down to the nearest millisecond. E.g., if the timestamp
represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond.
Convert a Timestamp to the number of seconds elapsed from the epoch.
The result will be rounded down to the nearest second. E.g., if the timestamp represents
"1969-12-31T23:59:59.999999999Z", it will be rounded to -1 second.
Convert Timestamp to RFC 3339 date string format. The output will always be Z-normalized and
uses 3, 6 or 9 fractional digits as required to represent the exact value. Note that Timestamp
can only represent time from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. Seehttps://www.ietf.org/rfc/rfc3339.txt
Example of generated format: "1972-01-01T10:00:20.021Z"
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Class Timestamps (3.19.4)\n\n public final class Timestamps\n\nUtilities to help create/manipulate `protobuf/timestamp.proto`. All operations throw an\nIllegalArgumentException if the input(s) are not [valid](/java/docs/reference/protobuf/latest/com.google.protobuf.util.Timestamps#com_google_protobuf_util_Timestamps_isValid_com_google_protobuf_Timestamp_). \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e Timestamps \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Fields\n-------------\n\n### EPOCH\n\n public static final Timestamp EPOCH\n\nA constant holding the [Timestamp](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp) of epoch time, `1970-01-01T00:00:00.000000000Z`.\n\n### MAX_VALUE\n\n public static final Timestamp MAX_VALUE\n\nA constant holding the maximum valid [Timestamp](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp), `9999-12-31T23:59:59.999999999Z`.\n\n### MIN_VALUE\n\n public static final Timestamp MIN_VALUE\n\nA constant holding the minimum valid [Timestamp](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp), `0001-01-01T00:00:00Z`.\n\nStatic Methods\n--------------\n\n### add(Timestamp start, Duration length)\n\n public static Timestamp add(Timestamp start, Duration length)\n\nAdd a duration to a timestamp.\n\n### between(Timestamp from, Timestamp to)\n\n public static Duration between(Timestamp from, Timestamp to)\n\nCalculate the difference between two timestamps.\n\n### checkValid(Timestamp timestamp)\n\n public static Timestamp checkValid(Timestamp timestamp)\n\nThrows an IllegalArgumentException if the given [Timestamp](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp) is not valid.\n\n### checkValid(Timestamp.Builder timestampBuilder)\n\n public static Timestamp checkValid(Timestamp.Builder timestampBuilder)\n\nBuilds the given builder and throws an IllegalArgumentException if it is not valid. See\n[#checkValid(Timestamp)](/java/docs/reference/protobuf/latest/com.google.protobuf.util.Timestamps#com_google_protobuf_util_Timestamps_checkValid_com_google_protobuf_Timestamp_).\n\n### comparator()\n\n public static Comparator\u003cTimestamp\u003e comparator()\n\nReturns a [Comparator](https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html) for [Timestamps](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp) which sorts in increasing\nchronological order. Nulls and invalid [Timestamps](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp) are not allowed (see\n[#isValid](/java/docs/reference/protobuf/latest/com.google.protobuf.util.Timestamps#com_google_protobuf_util_Timestamps_isValid_)). The returned comparator is serializable.\n\n### compare(Timestamp x, Timestamp y)\n\n public static int compare(Timestamp x, Timestamp y)\n\nCompares two timestamps. The value returned is identical to what would be returned by: `\nTimestamps.comparator().compare(x, y)`.\n\n### fromDate(Date date)\n\n public static Timestamp fromDate(Date date)\n\nCreate a Timestamp from a java.util.Date. If the java.util.Date is a java.sql.Timestamp,\nfull nanonsecond precision is retained.\n\n### fromMicros(long microseconds)\n\n public static Timestamp fromMicros(long microseconds)\n\nCreate a Timestamp from the number of microseconds elapsed from the epoch.\n\n### fromMillis(long milliseconds)\n\n public static Timestamp fromMillis(long milliseconds)\n\nCreate a Timestamp from the number of milliseconds elapsed from the epoch.\n\n### fromNanos(long nanoseconds)\n\n public static Timestamp fromNanos(long nanoseconds)\n\nCreate a Timestamp from the number of nanoseconds elapsed from the epoch.\n\n### fromSeconds(long seconds)\n\n public static Timestamp fromSeconds(long seconds)\n\nCreate a Timestamp from the number of seconds elapsed from the epoch.\n\n### isValid(Timestamp timestamp)\n\n public static boolean isValid(Timestamp timestamp)\n\nReturns true if the given [Timestamp](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp) is valid. The `seconds` value must be in the\nrange \\[-62,135,596,800, +253,402,300,799\\] (i.e., between 0001-01-01T00:00:00Z and\n9999-12-31T23:59:59Z). The `nanos` value must be in the range \\[0, +999,999,999\\].\n\n**Note:** Negative second values with fractional seconds must still have non-negative\nnanos values that count forward in time.\n\n### isValid(long seconds, int nanos)\n\n public static boolean isValid(long seconds, int nanos)\n\nReturns true if the given number of seconds and nanos is a valid [Timestamp](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp). The `\nseconds` value must be in the range \\[-62,135,596,800, +253,402,300,799\\] (i.e., between\n0001-01-01T00:00:00Z and 9999-12-31T23:59:59Z). The `nanos` value must be in the range\n\\[0, +999,999,999\\].\n\n**Note:** Negative second values with fractional seconds must still have non-negative\nnanos values that count forward in time.\n\n### parse(String value)\n\n public static Timestamp parse(String value)\n\nParse from RFC 3339 date string to Timestamp. This method accepts all outputs of [#toString(Timestamp)](/java/docs/reference/protobuf/latest/com.google.protobuf.util.Timestamps#com_google_protobuf_util_Timestamps_toString_com_google_protobuf_Timestamp_) and it also accepts any fractional digits (or none) and any offset as\nlong as they fit into nano-seconds precision.\n\nExample of accepted format: \"1972-01-01T10:00:20.021-05:00\"\n\n### parseUnchecked(String value)\n\n public static Timestamp parseUnchecked(String value)\n\nParses a string in RFC 3339 format into a [Timestamp](/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp).\n\nIdentical to [#parse(String)](/java/docs/reference/protobuf/latest/com.google.protobuf.util.Timestamps#com_google_protobuf_util_Timestamps_parse_java_lang_String_), but throws an IllegalArgumentException instead\nof a [ParseException](https://docs.oracle.com/javase/8/docs/api/java/text/ParseException.html) if parsing fails.\n\n### subtract(Timestamp start, Duration length)\n\n public static Timestamp subtract(Timestamp start, Duration length)\n\nSubtract a duration from a timestamp.\n\n### toMicros(Timestamp timestamp)\n\n public static long toMicros(Timestamp timestamp)\n\nConvert a Timestamp to the number of microseconds elapsed from the epoch.\n\nThe result will be rounded down to the nearest microsecond. E.g., if the timestamp\nrepresents \"1969-12-31T23:59:59.999999999Z\", it will be rounded to -1 microsecond.\n\n### toMillis(Timestamp timestamp)\n\n public static long toMillis(Timestamp timestamp)\n\nConvert a Timestamp to the number of milliseconds elapsed from the epoch.\n\nThe result will be rounded down to the nearest millisecond. E.g., if the timestamp\nrepresents \"1969-12-31T23:59:59.999999999Z\", it will be rounded to -1 millisecond.\n\n### toNanos(Timestamp timestamp)\n\n public static long toNanos(Timestamp timestamp)\n\nConvert a Timestamp to the number of nanoseconds elapsed from the epoch.\n\n### toSeconds(Timestamp timestamp)\n\n public static long toSeconds(Timestamp timestamp)\n\nConvert a Timestamp to the number of seconds elapsed from the epoch.\n\nThe result will be rounded down to the nearest second. E.g., if the timestamp represents\n\"1969-12-31T23:59:59.999999999Z\", it will be rounded to -1 second.\n\n### toString(Timestamp timestamp)\n\n public static String toString(Timestamp timestamp)\n\nConvert Timestamp to RFC 3339 date string format. The output will always be Z-normalized and\nuses 3, 6 or 9 fractional digits as required to represent the exact value. Note that Timestamp\ncan only represent time from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. See\n\u003chttps://www.ietf.org/rfc/rfc3339.txt\u003e\n\nExample of generated format: \"1972-01-01T10:00:20.021Z\""]]