日期笔记

/**
     * 
     * @Title: getCountday
     * @Description: 去除周末的总天数
     * @author yjs
     * @date 2018年11月9日 上午9:14:11
     * @param strStartDate
     * @param strEndDate
     * @return
     * @throws java.text.ParseException
     */
    public int getCountday(String strStartDate, String strEndDate) throws java.text.ParseException {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = null;
        Date endDate = null;
        startDate = df.parse(strStartDate);
        endDate = df.parse(strEndDate);
        int result = 0;
        while (startDate.compareTo(endDate) <= 0) {
            if (startDate.getDay() != 6 && startDate.getDay() != 0)
                result++;
            startDate.setDate(startDate.getDate() + 1);
        }
        return result;

    }

    /**
     * 
     * @Title: dayDiff
     * @Description:计算两个字符串日期相差的天数
     * @author yjs
     * @date 2018年11月9日 下午3:30:54
     * @param date1 字符串日期1
     * @param date2 字符串日期2
     * @param format 日期格式化方式  format="yyyy-MM-dd"
     * @return
     */
    public static Long dayDiff(String date1, String date2, String format) {
        SimpleDateFormat formater = new SimpleDateFormat(format);
        Long diff = 0l;
        try {
            Long d1 = formater.parse(date1).getTime();
            Long d2 = formater.parse(date2).getTime();
            // diff = (Math.abs(d1 - d2) / (1000 * 60 * 60 * 24));
            diff = (d2 - d1) / (1000 * 60 * 60 * 24);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return diff;
    }
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值