Online Java Compiler By
JavaTpoint.com
import java.sql.Timestamp; public class JavaTimestampCompareToExample1 { public static void main(String[] args) { Timestamp ts1 = Timestamp.valueOf("2018-09-01 09:01:15"); Timestamp ts2 = Timestamp.valueOf("2018-09-01 09:01:16"); //compares ts1 with ts2 int b3 = ts1.compareTo(ts2); if(b3==0){ System.out.println("Both values are equal"); } else if(b3>0){ System.out.println("TimeSpan1 value is greater"); } else{ System.out.println("TimeSpan2 value is greater"); } } }
Output