Here you can find the source of compareTimstampStr(String timestamp1, String timestamp2, String format)
public static int compareTimstampStr(String timestamp1, String timestamp2, String format)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static int compareTimstampStr(String timestamp1, String timestamp2, String format) { int result = 10; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); long temp = 10L; try {//from w w w . j ava 2 s. c o m Date date1 = simpleDateFormat.parse(timestamp1); Date date2 = simpleDateFormat.parse(timestamp2); temp = date1.getTime() - date2.getTime(); } catch (ParseException e) { result = 0x7fffffff; e.printStackTrace(); } if (temp > 0L) result = 1; else if (temp == 0L) result = 0; else if (temp < 0L) result = -1; return result; } }