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;
}

 

相关文章:

  • 2022-02-10
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2021-07-05
相关资源
相似解决方案