DateUtil

Posted Orc_Warrior

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DateUtil相关的知识,希望对你有一定的参考价值。

1、比较两个日期是否是同一天

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date lastRecordTimeD = sdf.parse(lines[2]);

Calendar lastRecordTimeCal = new GregorianCalendar();

lastRecordTimeCal.setTime(lastRecordTimeD);

Calendar nowTime = Calendar.getInstance();

Calendar tempDate = (Calendar) nowTime.clone();

tempDate.set(Calendar.YEAR, lastRecordTimeCal.get(Calendar.YEAR));
tempDate.set(Calendar.MONTH, lastRecordTimeCal.get(Calendar.MONTH));
tempDate.set(Calendar.DAY_OF_MONTH,lastRecordTimeCal.get(Calendar.DAY_OF_MONTH));

//是否是同一天
boolean sameDay = false;

if (nowTime.equals(tempDate)) {
    sameDay = true;
}

 

以上是关于DateUtil的主要内容,如果未能解决你的问题,请参考以下文章