zoukankan      html  css  js  c++  java
  • java获取上周任意一天的日期

    /**
         * 获取上周周几的日期,默认一周从周一开始
         * @param dayOfWeek
         * @param weekOffset
         * @return
         */
        public static Date getDayOfWeek(int dayOfWeek,int weekOffset){
            return getDayOfWeek(Calendar.MONDAY,dayOfWeek,weekOffset);
        }
    
        /**
         * 获取上(下)周周几的日期
         * @param firstDayOfWeek {@link Calendar}
         * 值范围 <code>SUNDAY</code>,
         * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
         * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>
         * @param dayOfWeek {@link Calendar}
         * @param weekOffset  周偏移,上周为-1,本周为0,下周为1,以此类推
         * @return
         */
        public static Date getDayOfWeek(int firstDayOfWeek,int dayOfWeek,int weekOffset){
            if(dayOfWeek>Calendar.SATURDAY || dayOfWeek<Calendar.SUNDAY){
                return null;
            }
            if(firstDayOfWeek>Calendar.SATURDAY || firstDayOfWeek < Calendar.SUNDAY){
                return null;
            }
            Calendar date=Calendar.getInstance(Locale.CHINA);
            date.setFirstDayOfWeek(firstDayOfWeek);
            //周数减一,即上周
            date.add(Calendar.WEEK_OF_MONTH,weekOffset);
            //日子设为周几
            date.set(Calendar.DAY_OF_WEEK, dayOfWeek);
            //时分秒全部置0
            date.set(Calendar.HOUR_OF_DAY, 0);
            date.set(Calendar.MINUTE, 0);
            date.set(Calendar.SECOND, 0);
            date.set(Calendar.MILLISECOND, 0);
            return date.getTime();
        }
  • 相关阅读:
    小程序模板
    小程序 if else
    小程序入门小知识
    懒加载
    展示效果
    五星评价
    萤火虫效果
    下雪效果
    选项卡
    VUE组件中 data 里面的数据为什么要return 出来
  • 原文地址:https://www.cnblogs.com/winkey4986/p/7465521.html
Copyright © 2011-2022 走看看