Javatpoint Logo
Javatpoint Logo

Java Timestamp compareTo() Method

The compareTo () method of Timestamp class compares this Timestamp object to the given Timestamp object or to the given date object.



  • The parameter 'ts' represents the Timestamp object to be compared to this Timespan object.
  • The parameter 'o' represents the date to be compared to this Timespan object.


The compareTo() method of Timestamp class returns :

  • Integer value 0 if this Timestamp object is equal to given Timestamp object.
  • A value less than 0 if this Timespan object is before the given argument.
  • A value greater than 0 if this Timespan object is after the given argument.

Example 1

Test it Now


TimeSpan2 value is greater

Example 2

Test it Now


Geetanjali's birthTime is greater than Reema

Example 3

Test it Now


Expire Timespan: 2018-09-03 09:01:15.0
Today date: Sun Sep 02 20:27:12 IST 2018
Your plan has not expired. You can still avail our facility.
Next TopicJava Timestamp

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA