如何确定两日期是同一天在Nodejs当地时间吗

2024-12-03 16:46:49
推荐回答(1个)
回答1:

把二个时间的的年月日分别对比,完全相等就是同一天,代码下:privatestaticbooleanisSameDate(Datedate1,Datedate2){Calendarcal1=Calendar.getInstance();cal1.setTime(date1);Calendarcal2=Calendar.getInstance();cal2.setTime(date2);booleanisSameYear=cal1.get(Calendar.YEAR)==cal2.get(Calendar.YEAR);booleanisSameMonth=isSameYear&&cal1.get(Calendar.MONTH)==cal2.get(Calendar.MONTH);booleanisSameDate=isSameMonth&&cal1.get(Calendar.DAY_OF_MONTH)==cal2.get(Calendar.DAY_OF_MONTH);returnisSameDate;}