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.

Syntax

Parameters

  • 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.

Returns

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

Output:

TimeSpan2 value is greater

Example 2

Output:

Geetanjali's birthTime is greater than Reema

Example 3

Output:

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.