当前位置:   article > 正文

获取当前实际的后5天 跨月_java 获取每个月的倒数第5天

java 获取每个月的倒数第5天
/**
     * @param date string 转日期
     * @return
     */
    public static Date transBackDate(String date) {
        Date parse = new Date();
        try {
            if (date=="" || date.equals("0") || date.equals(null) || date.equals("null")){
                return  format.parse("19700101");
            }
            Date  date1 =  format.parse(date);


            long time = date1.getTime();
            long newTime = time + 5 * 24 * 60 * 60 * 1000;

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(newTime);
            Integer year = calendar.get(Calendar.YEAR);
            Integer month = calendar.get(Calendar.MONTH) + 1;
            String monthString = "";
            String dayString = "";
            if (month < 10) {
                monthString = "0" + month.toString();
            } else {
                monthString = month.toString();
            }

            Integer day = (calendar.get(Calendar.DATE));
            if (day < 10) {
                dayString = "0" + day.toString();
            } else {
                dayString = day.toString();
            }
            StringBuilder sbVar1 = new StringBuilder();
            String date2 = sbVar1.append(year).append(monthString).append(dayString).toString();
            parse =  format.parse(date2);

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return parse;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/313757
推荐阅读
相关标签
  

闽ICP备14008679号