package com.demo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo05 {
public static void main(String[] args) throws Exception {
//设置转换的日期格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//开始时间
Date startDate = sdf.parse("2018-05-10");
//结束时间
Date endDate = sdf.parse("2018-11-10");
//得到相差的天数 betweenDate
long betweenDate = (endDate.getTime() - startDate.getTime())/(60*60*24*1000);
//打印控制台相差的天数
System.out.println(betweenDate);
}
}
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/17569.html