Java tutorial
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; public class Main { public static int timeCompare(String str1, String str2) { try { SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date begin = dfs.parse(str1); java.util.Date end = dfs.parse(str2); long between = end.getTime() - begin.getTime(); if (between > 0) { return 1; } else if (between == 0) { return 0; } else { return -1; } } catch (Exception e) { return 1; } } }