public static long getDay(String data) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //给定的时间 Date d= null; try { d = format.parse(data); } catch (Exception e) { e.printStackTrace(); } //当前时间处理 Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); //给定时间处理 Calendar setCal = Calendar.getInstance(); setCal.setTime(d); setCal.set(Calendar.HOUR_OF_DAY, 0); setCal.set(Calendar.MINUTE, 0); setCal.set(Calendar.SECOND, 0); setCal.set(Calendar.MILLISECOND, 0); long dayDiff =(setCal.getTimeInMillis()-cal.getTimeInMillis())/(1000*60*60*24); return dayDiff; } public static void main(String[] args){ System.out.println( getDay("2018-05-30 23:59:00")); }
两个时间返回天数
最新推荐文章于 2022-08-16 09:33:10 发布