取两个日期时间戳然后相减,得出相差的毫秒书,然后换算成天

解决方案 »

  1.   

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.*;public class Datesub {
    public static void main(String[] args) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    java.util.Date d = sdf.parse("2007-03-01"); 
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    long timethis = calendar.getTimeInMillis();
    calendar.setTime(d);
    long timeend = calendar.getTimeInMillis();
    long theday = (timeend - timethis) / (1000 * 60 * 60 * 24);
    System.out.print(theday);
    }
    }