zoukankan      html  css  js  c++  java
  • calendar插件遇到闰年2月错误日期bug

    学习自:https://blog.csdn.net/dongyuxu342719/article/details/78131697

    开发时遇到的,十二个月就到二月份有问题,刚开始以为是自己改时间戳整的,结果发现并不是,后加了一段代码解决(图中!!!!就是),好像意思是清缓存。

    public Long getLastDayOfMonth(int year,int month){
            Long lastDays =0l;
            Calendar cal = Calendar.getInstance();
            cal.clear();  //!!!!!!!!!!!!!!!!!!!!!!!!!
            //设置年份
            cal.set(Calendar.YEAR,year);
            //设置月份
            cal.set(Calendar.MONTH, month-1);
            //获取某月最大天数
            int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            //设置日历中月份的最大天数
            cal.set(Calendar.DAY_OF_MONTH, lastDay);
            //格式化日期
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String lastDayOfMonth = sdf.format(cal.getTime());
            try {
                lastDays = sdf.parse(lastDayOfMonth).getTime();
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return lastDays;
        }
  • 相关阅读:
    Jmeter运行原理
    hihoOffer收割练习20题目2
    hihoOffer收割练习20题目1
    STL-map容器
    STL-map容器
    2017多校合练1
    2017多校合练1
    STL之map基础知识
    STL之map基础知识
    DP入门
  • 原文地址:https://www.cnblogs.com/caixiaoyou/p/10040484.html
Copyright © 2011-2022 走看看