Java 计算两个日期之间的相差天数

代码如下

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);
    }

}

猜你喜欢

转载自blog.csdn.net/CHYabc123456hh/article/details/107508848