java中获取动态输入的两个日期,并计算两个日期相差多少天???
2个回答
展开全部
String str1 = "2014-11-20";
DateFormat fmtDateTime = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = fmtDateTime.parse(str1.toString());
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(date1);
Calendar today = Calendar.getInstance();
double days = (today.getTimeInMillis() - calendar1.getTimeInMillis()) / (1000 * 60 * 60 * 24);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询