zoukankan      html  css  js  c++  java
  • 求两个日期的周

    public List<WeekYearVO> dayOfWeekList(Integer startDate, Integer endDate){
        String startTime = String.valueOf(startDate);
        String endTime = String.valueOf(endDate);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = formatter.parse(startTime);
        Date parse1 = formatter.parse(endTime);
        String startTimeDate = simpleDateFormat.format(parse);
        String endTimeDate = simpleDateFormat.format(parse1);
        DateTime startDateTime =DateTime.parse(startTimeDate);
        DateTime endDateTime = DateTime.parse(endTimeDate);
    
        Days days = Days.daysBetween(startDateTime, endDateTime);
        int dayCount = days.getDays();
        List<WeekYearVO> result = Lists.newArrayList();
        for (int i = 0; i <= (dayCount/7)+1; i++) {
            DateTime standardDate = startDateTime.plusWeeks(i);
            DateTime startBond = standardDate.withDayOfWeek(1);
            DateTime endBond = standardDate.withDayOfWeek(7);
            Integer week = standardDate.getWeekOfWeekyear();
            Integer year = standardDate.getWeekyear();
            WeekYearVO weekYear = new WeekYearVO(startBond.isBefore(startDateTime) ? startDateTime : startBond,
                    endBond.isAfter(endDateTime) ? endDateTime : endBond,
                    week,
                    year);
            result.add(weekYear);
        }
        return result;
    }
    public class WeekYearVO {
        private DateTime startDate;
        private DateTime endDate;
        private Integer week;
        private Integer year;
    }
  • 相关阅读:
    DataGridView
    View Designer
    错题集
    MetalKit_1
    倍道而行:选择排序
    ARKit_3_任意门
    ARKit__2_尺子项目
    关于scrollview的无限滚动效果实现
    tableview折叠动效
    NSURLSession的简单使用
  • 原文地址:https://www.cnblogs.com/lqblods/p/15494656.html
Copyright © 2011-2022 走看看