Java 计算两个日期之间的相差天数
程序员文章站
2022-07-12 17:49:30
...
代码如下
package com.data.dp;
import org.apache.commons.lang3.StringUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class testDate {
public static void main(String[] args) throws ParseException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String closeDate = StringUtils.deleteWhitespace("2020-05-22");
String startDate = StringUtils.deleteWhitespace("2019-05-22");
int days = (int)((df.parse(closeDate).getTime()-df.parse(startDate).getTime())/(24 * 60 * 60 * 1000));
System.out.println(days);
}
}