Java Timestamp.compareTo(Date o)

Syntax

Timestamp.compareTo(Date o) has the following syntax.

public int compareTo(Date o)

Example

In the following code shows how to use Timestamp.compareTo(Date o) method.


import java.util.Date;
// w w  w.j  a v a 2s.  c  om
public class Main {
  public static void main(String[] args) {
    java.sql.Timestamp ts1 = java.sql.Timestamp.valueOf("2012-04-06 09:01:10");
    java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2013-04-06 09:01:10");
    
    System.out.println(ts1.compareTo(new Date()));

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.sql »




DatabaseMetaData
ParameterMetaData
PreparedStatement
ResultSet
Timestamp