Class Timestamp (2.48.0)

publicfinalclassTimestampimplementsComparable<Timestamp>,Serializable

Represents a timestamp with nanosecond precision. Timestamps cover the range [0001-01-01, 9999-12-31].

Timestamp instances are immutable.

Static Fields

MAX_VALUE

publicstaticfinalTimestampMAX_VALUE

The largest legal timestamp ("9999-12-31T23:59:59Z").

Field Value
TypeDescription
Timestamp

MIN_VALUE

publicstaticfinalTimestampMIN_VALUE

The smallest legal timestamp ("0001-01-01T00:00:00Z").

Field Value
TypeDescription
Timestamp

Static Methods

fromProto(Timestamp proto)

publicstaticTimestampfromProto(Timestampproto)

Creates an instance of Timestamp fromcom.google.protobuf.Timestamp.

Parameter
NameDescription
protoTimestamp
Returns
TypeDescription
Timestamp

now()

publicstaticTimestampnow()

Creates an instance with current time.

Returns
TypeDescription
Timestamp

of(Timestamp timestamp)

publicstaticTimestampof(Timestamptimestamp)

Creates an instance representing the value oftimestamp.

Parameter
NameDescription
timestampTimestamp
Returns
TypeDescription
Timestamp

of(Date date)

publicstaticTimestampof(Datedate)

Creates an instance representing the value ofDate.

Parameter
NameDescription
dateDate
Returns
TypeDescription
Timestamp

ofTimeMicroseconds(long microseconds)

publicstaticTimestampofTimeMicroseconds(longmicroseconds)

Creates an instance representing the value ofmicroseconds.

Parameter
NameDescription
microsecondslong
Returns
TypeDescription
Timestamp

ofTimeSecondsAndNanos(long seconds, int nanos)

publicstaticTimestampofTimeSecondsAndNanos(longseconds,intnanos)

Creates an instance representing the value ofseconds andnanos since January 1, 1970, 00:00:00 UTC.

Parameters
NameDescription
secondslong

seconds since January 1, 1970, 00:00:00 UTC. A negative value is the number of seconds before January 1, 1970, 00:00:00 UTC.

nanosint

the fractional seconds component, in the range 0..999999999.

Returns
TypeDescription
Timestamp

parseTimestamp(String timestamp)

publicstaticTimestampparseTimestamp(Stringtimestamp)
Parameter
NameDescription
timestampString
Returns
TypeDescription
Timestamp

parseTimestampDuration(String timestamp)

publicstaticTimestampparseTimestampDuration(Stringtimestamp)

Creates a Timestamp instance from the given string. Input string should be in the RFC 3339 format, like '2020-12-01T10:15:30.000Z' or with the timezone offset, such as '2020-12-01T10:15:30+01:00'.

Parameter
NameDescription
timestampString

string in the RFC 3339 format

Returns
TypeDescription
Timestamp

created Timestamp

Methods

compareTo(Timestamp other)

publicintcompareTo(Timestampother)
Parameter
NameDescription
otherTimestamp
Returns
TypeDescription
int

equals(Object o)

publicbooleanequals(Objecto)
Parameter
NameDescription
oObject
Returns
TypeDescription
boolean
Overrides

getNanos()

publicintgetNanos()

Returns the fractional seconds component, in nanoseconds.

Returns
TypeDescription
int

getSeconds()

publiclonggetSeconds()

Returns the number of seconds since January 1, 1970, 00:00:00 UTC. A negative value is the number of seconds before January 1, 1970, 00:00:00 UTC.

Returns
TypeDescription
long

hashCode()

publicinthashCode()
Returns
TypeDescription
int
Overrides

toDate()

publicDatetoDate()

Returns a newjava.util.Date corresponding to thistimestamp. Any sub-millisecond precision will be stripped.

Returns
TypeDescription
Date

An approximatejava.util.Date representation of thistimestamp.

toProto()

publicTimestamptoProto()

Returns acom.google.protobuf.Timestamp initialized to the same point in time as this.

Returns
TypeDescription
Timestamp

toSqlTimestamp()

publicTimestamptoSqlTimestamp()

Returns a JDBC timestamp initialized to the same point in time asthis.

Returns
TypeDescription
Timestamp

toString()

publicStringtoString()
Returns
TypeDescription
String
Overrides

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-31 UTC.