public long getdays(String endDatestr,String startDatestr){ SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd"); long hours=0; try { Date startDate= sdf.parse(startDatestr); Date endDate = sdf.parse(endDatestr); //确保startDatestr在endDatestr的前面 if(startDate.before(endDate)){ Date da = startDate; startDate=endDate; endDate = da; } hours= (endDate.getTime()-startDate.getTime())/(1000*60*60); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return hours; }
例如输入getdays(“1986-05-05”,“1986-05-04”)运行结果23;
输入getdays(“1991-09-15”,“1991-09-14”)运行结果25;
这是怎么回事啊 代码写错了码?
慕移动4708697
相关分类