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.

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

Test it Now

Output:

TimeSpan2 value is greater

Example 2

Test it Now

Output:

Geetanjali's birthTime is greater than Reema

Example 3

Test it Now

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.
Next TopicJava Timestamp





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA