Java examples for java.util:Date Compare
compare two time by date ,ignore HH:mm:ss
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**// ww w. ja va 2s.com * 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; } } }