提供两个指定格式字符串,返回两个日期的时间间隔-百家乐凯发k8
import java.text.parseexception;
import java.text.simpledateformat;
import java.util.date;
public class dept {
public static void main(string[] args) {
getdeltime("2020-12-10", "2021-1-12");
}
public static long getdeltime(string starttime,string endtime){
simpledateformat sdf=new simpledateformat("yyyy-mm-dd");
date startdate= null;
date enddate= null;
try {
startdate = sdf.parse(starttime);
enddate = sdf.parse(endtime);
} catch (parseexception e) {
e.printstacktrace();
}
long time = (enddate.gettime() - startdate.gettime()) / (1000 * 60 * 60 * 24);
system.out.println(time);
return time;
}
}