java判断两个时间是不是同一天的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:publicclassTimeUtil{publicstaticfinalintSECONDS_IN_DAY=60*60*...
复制代码 代码如下:
public class TimeUtil {
public static final int SECONDS_IN_DAY = 60 * 60 * 24;
public static final long MILLIS_IN_DAY = 1000L * SECONDS_IN_DAY;
public static boolean isSameDayOfMillis(final long ms1, final long ms2) {
final long interval = ms1 - ms2;
return interval < MILLIS_IN_DAY
&& interval > -1L * MILLIS_IN_DAY
&& toDay(ms1) == toDay(ms2);
}
private static long toDay(long millis) {
return (millis + TimeZone.getDefault().getOffset(millis)) / MILLIS_IN_DAY;
}
}