一、获取2015-09-18 00:00:00.0
Calendar currentCalendar=Calendar.getInstance(); Date currentDateTime=currentCalendar.getTime(); Calendar cl=Calendar.getInstance(); cl.set(currentCalendar.get(Calendar.YEAR), currentCalendar.get(Calendar.MONTH), currentCalendar.get(Calendar.DATE),0, 0, 0); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd"); String str=sdf.format(cl.getTime()); System.out.println(sdf.format(sdf2.parse(str)));
二、获取2个时间的 差多少天
Date currentDateTime=Calendar.getInstance().getTime(); Date dataCreateDate=Calendar.getInstance().getTime(); long diff = dataCreateDate.getTime() - currentDateTime.getTime(); long days = diff / (1000 * 60 * 60 * 24);
时间: 2025-01-16 04:54:47