Upgrade warning: in prior version 1.17, this method required milliseconds to be exactly 3
digits (if included), and did not throw an exception for all types of invalid input values, but
starting in version 1.18, the parsing done by this method has become more strict to enforce
that only valid RFC3339 strings are entered, and if not, it throws a NumberFormatException. Also, in accordance with the RFC3339 standard, any number of
milliseconds digits is now allowed.
Any time information beyond millisecond precision is truncated.
For the date-only case, the time zone is ignored and the hourOfDay, minute, second, and
millisecond parameters are set to zero.
Upgrade warning: in prior version 1.17, this method required milliseconds to be exactly 3
digits (if included), and did not throw an exception for all types of invalid input values, but
starting in version 1.18, the parsing done by this method has become more strict to enforce
that only valid RFC3339 strings are entered, and if not, it throws a NumberFormatException. Also, in accordance with the RFC3339 standard, any number of
milliseconds digits is now allowed.
[[["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-08-28 UTC."],[],[],null,["# Class DateTime (2.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0 (latest)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.DateTime)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.DateTime)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.DateTime)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.DateTime)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.DateTime)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.DateTime)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.DateTime)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.DateTime) \n\n public final class DateTime implements Serializable\n\nImmutable representation of a date with an optional time and an optional time zone based on [RFC 3339](http://tools.ietf.org/html/rfc3339).\n\nImplementation is immutable and therefore thread-safe. \n\nInheritance\n-----------\n\n[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e DateTime \n\nImplements\n----------\n\n[Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) \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 Methods\n--------------\n\n### parseRfc3339(String str)\n\n public static DateTime parseRfc3339(String str)\n\nParses an RFC3339 date/time value.\n\nUpgrade warning: in prior version 1.17, this method required milliseconds to be exactly 3\ndigits (if included), and did not throw an exception for all types of invalid input values, but\nstarting in version 1.18, the parsing done by this method has become more strict to enforce\nthat only valid RFC3339 strings are entered, and if not, it throws a NumberFormatException. Also, in accordance with the RFC3339 standard, any number of\nmilliseconds digits is now allowed.\n\nAny time information beyond millisecond precision is truncated.\n\nFor the date-only case, the time zone is ignored and the hourOfDay, minute, second, and\nmillisecond parameters are set to zero.\n\n### parseRfc3339ToSecondsAndNanos(String str)\n\n public static DateTime.SecondsAndNanos parseRfc3339ToSecondsAndNanos(String str)\n\nParses an RFC3339 timestamp to a pair of seconds and nanoseconds since Unix Epoch.\n\nConstructors\n------------\n\n### DateTime(boolean dateOnly, long value, Integer tzShift)\n\n public DateTime(boolean dateOnly, long value, Integer tzShift)\n\nInstantiates [DateTime](/java/docs/reference/google-http-client/latest/com.google.api.client.util.DateTime), which may represent a date-only value, from the number of\nmilliseconds since the Unix epoch, and a shift from UTC in minutes.\n\n### DateTime(String value)\n\n public DateTime(String value)\n\nInstantiates [DateTime](/java/docs/reference/google-http-client/latest/com.google.api.client.util.DateTime) from an [RFC 3339](http://tools.ietf.org/html/rfc3339)\ndate/time value.\n\nUpgrade warning: in prior version 1.17, this method required milliseconds to be exactly 3\ndigits (if included), and did not throw an exception for all types of invalid input values, but\nstarting in version 1.18, the parsing done by this method has become more strict to enforce\nthat only valid RFC3339 strings are entered, and if not, it throws a NumberFormatException. Also, in accordance with the RFC3339 standard, any number of\nmilliseconds digits is now allowed.\n\n### DateTime(Date value)\n\n public DateTime(Date value)\n\nInstantiates [DateTime](/java/docs/reference/google-http-client/latest/com.google.api.client.util.DateTime) from a [Date](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html).\n\nThe time zone is interpreted as `TimeZone.getDefault()`, which may vary with\nimplementation.\n\n### DateTime(Date date, TimeZone zone)\n\n public DateTime(Date date, TimeZone zone)\n\nInstantiates [DateTime](/java/docs/reference/google-http-client/latest/com.google.api.client.util.DateTime) from a [Date](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html) and [TimeZone](https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html).\n\n### DateTime(long value)\n\n public DateTime(long value)\n\nInstantiates [DateTime](/java/docs/reference/google-http-client/latest/com.google.api.client.util.DateTime) from the number of milliseconds since the Unix epoch.\n\nThe time zone is interpreted as `TimeZone.getDefault()`, which may vary with\nimplementation.\n\n### DateTime(long value, int tzShift)\n\n public DateTime(long value, int tzShift)\n\nInstantiates [DateTime](/java/docs/reference/google-http-client/latest/com.google.api.client.util.DateTime) from the number of milliseconds since the Unix epoch, and a shift\nfrom UTC in minutes.\n\nMethods\n-------\n\n### equals(Object o)\n\n public boolean equals(Object o)\n\nA check is added that the time zone is the same. If you ONLY want to check equality of time\nvalue, check equality on the [#getValue()](/java/docs/reference/google-http-client/latest/com.google.api.client.util.DateTime#com_google_api_client_util_DateTime_getValue__).\n\n**Overrides** \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)\n\n### getTimeZoneShift()\n\n public int getTimeZoneShift()\n\nReturns the time zone shift from UTC in minutes or `0` for date-only value.\n\n### getValue()\n\n public long getValue()\n\nReturns the date/time value expressed as the number of milliseconds since the Unix epoch.\n\nIf the time zone is specified, this value is normalized to UTC, so to format this date/time\nvalue, the time zone shift has to be applied.\n\n### hashCode()\n\n public int hashCode()\n\n**Overrides** \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)\n\n### isDateOnly()\n\n public boolean isDateOnly()\n\nReturns whether this is a date-only value.\n\n### toString()\n\n public String toString()\n\n**Overrides** \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)\n\n### toStringRfc3339()\n\n public String toStringRfc3339()\n\nFormats the value as an RFC 3339 date/time string."]]