public class Test {
public static void main(String[] args) throws Exception {
SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
String time1="2019-01-31 00:00:01";
String time2="2019-02-03 23:59:59";
java.util.Date date1 = format.parse(time1);
java.util.Date date2 = format.parse(time2);
long time11 = date1.getTime();
long time22 = date2.getTime();
System.out.println(time11);
System.out.println(time22);
//时间戳转化int类型日期
int straDate = LDateTime.getIntDate(time11);
int endDate = LDateTime.getIntDate(time22);
System.err.println(straDate+"----"+endDate);
int days = (int) (((time11 - time22) / (1000*3600*24)));
int day = (int) ((time22 - time11) / (1000*3600*24));
if (day==0) {
System.out.println("相隔天数"+"当天");
}else {
System.out.println("相隔天数"+(Math.abs(days)));
}
}
}
public static final DateFormat FORMAT_YYYYMMDD = new SimpleDateFormat("yyyyMMdd");
public static int getIntDate(long time) {
return Integer.parseInt(FORMAT_YYYYMMDD.format(new Date(time)));
}
求两个时间相隔的天数
最新推荐文章于 2022-10-17 12:38:22 发布