String day1="1994:10:04"; String day2="1994:10:03"; SimpleDateFormat format= new SimpleDateFormat("yyyy:MM:dd"); try{ //转换Date格式 Date date4=format.parse(day1); Date date5=format.parse(day2); // long time1=date4.getTime();//获取毫秒 // long time2=date5.getTime(); // double days=((time1-time2)/(1000*60*60*24)); // System.out.println("相差"+days+"天"); Calendar cal=Calendar.getInstance(); cal.setTime(date4); int time3=cal.get(Calendar.DAY_OF_YEAR); cal.setTime(date5); int time4=cal.get(Calendar.DAY_OF_YEAR); int days=time3-time4; System.out.println("相差"+days+"天"); }catch(Exception e){ }
时间: 2024-10-08 02:20:10