Java tutorial
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * SimpleDateFormat with pattern yyyyMMdd */ private static SimpleDateFormat formatYYYYMMDD; /** * compare two time by date ,ignore HH:mm:ss * * @param ltime * @param rtime * @return */ public static int compareDay(long ltime, long rtime) { int lValue = Integer.valueOf(formatYYYYMMDD.format(new Date(ltime))); int rValue = Integer.valueOf(formatYYYYMMDD.format(new Date(rtime))); if (lValue > rValue) {//ascending by YYYYMMDD return 1; } else if (lValue < rValue) { return -1; } else { return 0; } } }