java获取日期之间天数的方法
程序员文章站
2024-03-05 21:39:07
本文实例讲述了java获取日期之间天数的方法。分享给大家供大家参考。具体实现方法如下:
private int daysbetween(date now, dat...
本文实例讲述了java获取日期之间天数的方法。分享给大家供大家参考。具体实现方法如下:
private int daysbetween(date now, date returndate) { calendar cnow = calendar.getinstance(); calendar creturndate = calendar.getinstance(); cnow.settime(now); creturndate.settime(returndate); settimetomidnight(cnow); settimetomidnight(creturndate); long todayms = cnow.gettimeinmillis(); long returnms = creturndate.gettimeinmillis(); long intervalms = todayms - returnms; return millisecondstodays(intervalms); } private int millisecondstodays(long intervalms) { return (int) (intervalms / (1000 * 86400)); } private void settimetomidnight(calendar calendar) { calendar.set(calendar.hour_of_day, 0); calendar.set(calendar.minute, 0); calendar.set(calendar.second, 0); }
希望本文所述对大家的java程序设计有所帮助。