当前位置: 代码网 > it编程>编程语言>Java > 基于Java实现根据周次生成数据的工具类

基于Java实现根据周次生成数据的工具类

2025年08月13日 Java 我要评论
摘要本文介绍了一个基于java的周次生成工具,用于根据指定的年份和周次类型(自然周或财务周)生成连续的周次列表数据。需求描述根据周次类型,生成连续的周次列表数据。周次类型分2种:自然周:周一至周日财务

摘要

本文介绍了一个基于java的周次生成工具,用于根据指定的年份和周次类型(自然周或财务周)生成连续的周次列表数据。

需求描述

根据周次类型,生成连续的周次列表数据。

周次类型分2种:

  • 自然周:周一至周日
  • 财务周:周五至下周四

特殊要求:

  • 按某年第一个周止日(类型为自然周时,是某年第一个周日),计算得到某年的第一周。
  • 按周止日算年份、月份;若周起日是当年,而周止日是下一年,则对应周算入下一年的第一周。

最终效果展示

效果:(自然周)

效果:(财务周)

实现步骤

1.定义周次类型枚举

包括自然周和财务周,并指定了每种周次的起始和结束日期对应的星期几。

import java.util.calendar;

/**周次类型*/
public enum weekkindenum {
    // 周一到周日
    g("g", calendar.monday,calendar.sunday,"自然周"),
    // 周五到下周四
    f("f",calendar.friday,calendar.thursday,"财务周");
    weekkindenum(string code, int beginnum, int endnum, string desc) {
        this.code = code;
        this.beginnum = beginnum;
        this.endnum = endnum;
        this.desc = desc;
    }
    private string code;
    private int beginnum;
    private int endnum;
    private string desc;

    public string getcode() {
        return code;
    }

    public int getbeginnum() {
        return beginnum;
    }

    public int getendnum() {
        return endnum;
    }

    public string getdesc() {
        return desc;
    }
}

2.定义周次实体

用于存储周次的相关信息,如年份、周起止日期、周次、周描述、所属年月等。

import java.text.simpledateformat;
import java.util.date;

/**
 * @classname weekentity
 * @description 周次
 * @date 2024/11/8 23:29
 * @author yqwang
 */
public class weekentity {
    /*年*/
    private string year;
    /*周起*/
    private date begindate;
    /*周止*/
    private date enddate;
    /*周次(某年第几周)*/
    private int week;
    /*周描述*/
    private string weekdesc;
    /*周次(某月第几周)*/
    private int weekmonth;
    /*所属年月yyyy-mm*/
    private string yearmonth;
    /*所属年月yyyy-mm-01*/
    private date yearmonthdate;
    /*类型:g(general)自然周f(finance)财务周*/
    private string kindid;

    public string getyear() {
        return year;
    }

    public void setyear(string year) {
        this.year = year;
    }

    public date getbegindate() {
        return begindate;
    }

    public void setbegindate(date begindate) {
        this.begindate = begindate;
    }

    public date getenddate() {
        return enddate;
    }

    public void setenddate(date enddate) {
        this.enddate = enddate;
    }

    public int getweek() {
        return week;
    }

    public void setweek(int week) {
        this.week = week;
    }

    public string getweekdesc() {
        return weekdesc;
    }

    public void setweekdesc(string weekdesc) {
        this.weekdesc = weekdesc;
    }

    public int getweekmonth() {
        return weekmonth;
    }

    public void setweekmonth(int weekmonth) {
        this.weekmonth = weekmonth;
    }

    public string getyearmonth() {
        return yearmonth;
    }

    public void setyearmonth(string yearmonth) {
        this.yearmonth = yearmonth;
    }

    public date getyearmonthdate() {
        return yearmonthdate;
    }

    public void setyearmonthdate(date yearmonthdate) {
        this.yearmonthdate = yearmonthdate;
    }

    public string getkindid() {
        return kindid;
    }

    public void setkindid(string kindid) {
        this.kindid = kindid;
    }

    @override
    public string tostring() {
        return "weekentity{" +
                "year='" + year + '\'' +
                ", begindate=" + formatdate(begindate) +
                ", enddate=" + formatdate(enddate) +
                ", week=" + week +
                ", weekdesc='" + weekdesc + '\'' +
                ", weekmonth=" + weekmonth +
                ", yearmonth='" + yearmonth + '\'' +
                ", yearmonthdate=" + formatdate(yearmonthdate) +
                ", kindid='" + kindid + '\'' +
                '}';
    }
    private static string formatdate(date date) {
        simpledateformat sdf = new simpledateformat("yyyy-mm-dd");
        return sdf.format(date);
    }
}

3.编写生成工具类

编写了生成工具类weekofmonthcalcutil,其中包含了generateweeks方法,用于根据年份和周次类型生成周次列表。该方法首先获取第一周的起止日期,然后循环得到每年的每周,并设置周次实体的其他属性值。

import java.text.dateformat;
import java.text.parseexception;
import java.text.simpledateformat;
import java.util.arraylist;
import java.util.calendar;
import java.util.date;
import java.util.list;

/**
 * @classname weekofmonthcalcutil
 * @description 用于生成年份的周次(自然周、财务周)信息
 * @date 2024/11/8 16:41
 * @author yqwang
 */
public class weekofmonthcalcutil {

    public static void main(string[] args) {
    	// 自然周
        list<weekentity> weeks = generateweeks(2023, weekkindenum.g);
        weeks.addall(generateweeks(2024, weekkindenum.g));
        // 还需要财务周? 
        // weeks.addall(generateweeks(2024, weekkindenum.f));
        // 打印结果
        for (weekentity week : weeks) {
            system.out.println(week);
        }
    }

    /**
     * @title:generateweeks
     * @param year 需要生成周次的年份
     * @param weekkindenum 周次类型
     * @return 周次列表
     */
    public static list<weekentity> generateweeks(int year, weekkindenum weekkindenum) {
        list<weekentity> weeks = new arraylist<>(53);
        // 1.获取第一周的起止日期
        calendar weekstart = getfirstweekstart(year, weekkindenum);
        // 今年的第几周
        int yearweek = 1;
        while (weekstart.get(calendar.year) <= year){
            // 2.循环得到今年的每周,终止条件:开始年份<=目标年份
            weekentity row = new weekentity();
            row.setyear(string.valueof(year));
            row.setbegindate(weekstart.gettime());
            // 周止
            calendar weekend = (calendar) weekstart.clone();
            weekend.add(calendar.day_of_year, 6);
            row.setenddate(weekend.gettime());
            if(weekend.get(calendar.year) > year){
                // 周止是下一年,则退出(会算到下一年的第一周)
                break;
            }

            // 设置其他属性值
            row.setweek(yearweek);
            // 第1周(24.12.30~25.01.05)
            row.setweekdesc(string.format("第%s周(%s~%s)",yearweek,formatdate(row.getbegindate(),"yy.mm.dd"),formatdate(row.getenddate(),"yy.mm.dd")));
            // (正常以[周止]判断所属月;特殊:止是下一年,则以[周起判断所属月])
            calendar belongdate = weekend;
            if(weekend.get(calendar.year) > year){
                belongdate = weekstart;
            }
            // 所属年月yyyy-mm
            row.setyearmonth(formatdate(belongdate,"yyyy-mm"));
            // 所属年月yyyy-mm-01
            row.setyearmonthdate(truncdate(belongdate,"yyyy-mm"));

            // 所属周的当月第几周(若周止所在月天>=7,则周次-1)
            int dayofweek = weekend.get(calendar.day_of_month);
            int weekmonth = (int) math.floor((dayofweek-0.1)/7)+1;
            row.setweekmonth(weekmonth);

            // 类型
            row.setkindid(weekkindenum.getcode());
            weeks.add(row);

            // 3.周+1
            yearweek ++;
            weekstart.add(calendar.day_of_year, 7);
        }

        return weeks;
    }
    /**返回yyyy-mm-dd格式*/
    @suppresswarnings("unused")
	private static string formatdate(calendar calendar) {
        return formatdate(calendar.gettime());
    }
    /**返回yyyy-mm-dd格式*/
    private static string formatdate(date date) {
        return formatdate(date,"yyyy-mm-dd");
    }
    /**返回指定格式*/
    private static string formatdate(calendar calendar,string pattern){
        return formatdate(calendar.gettime(),pattern);
    }
    /**返回指定格式*/
    private static string formatdate(date date,string pattern){
        if (date == null ) {
            throw new illegalargumentexception("date and format must not be null");
        }
        simpledateformat sdf = new simpledateformat(pattern);
        return sdf.format(date);
    }

    /**日期截取*/
    private static date truncdate(calendar calendar,string pattern){
        return truncdate(calendar.gettime(),pattern);
    }
    /**日期截取*/
    private static date truncdate(date date,string pattern){
        string datestr = formatdate(date,pattern);
        dateformat df = new simpledateformat(pattern);
        try {
            return df.parse(datestr);
        } catch (parseexception e) {
            e.printstacktrace();
        }
        return null;
    }
    /**
     * 获取某年第一个的周起日
     * 说明:通过某年第一个周止,往前推6天,即可得到周起日
     * */
    private static calendar getfirstweekstart(int year, weekkindenum weekkindenum) {
        // yyyy-01-01
        calendar end = calendar.getinstance();
        end.set(year, calendar.january, 1);
        // 1.拿到某年第一个周止
        while(true){
            // 2.当前是否是周止,不是则加1天,继续判断
            if(end.get(calendar.day_of_week)== weekkindenum.getendnum()){
                break;
            }
            // +1天
            end.add(calendar.day_of_month, 1);
        }
        // 3.返回周起日
        end.add(calendar.day_of_year, -6);
        return end;
    }

}

4.main()方法运行效果测试

weekentity{year='2023', begindate=2022-12-26, enddate=2023-01-01, week=1, weekdesc='第1周(22.12.26~23.01.01)', weekmonth=1, yearmonth='2023-01', yearmonthdate=2023-01-01, kindid='g'}
weekentity{year='2023', begindate=2023-01-02, enddate=2023-01-08, week=2, weekdesc='第2周(23.01.02~23.01.08)', weekmonth=2, yearmonth='2023-01', yearmonthdate=2023-01-01, kindid='g'}
weekentity{year='2023', begindate=2023-01-09, enddate=2023-01-15, week=3, weekdesc='第3周(23.01.09~23.01.15)', weekmonth=3, yearmonth='2023-01', yearmonthdate=2023-01-01, kindid='g'}
weekentity{year='2023', begindate=2023-01-16, enddate=2023-01-22, week=4, weekdesc='第4周(23.01.16~23.01.22)', weekmonth=4, yearmonth='2023-01', yearmonthdate=2023-01-01, kindid='g'}
weekentity{year='2023', begindate=2023-01-23, enddate=2023-01-29, week=5, weekdesc='第5周(23.01.23~23.01.29)', weekmonth=5, yearmonth='2023-01', yearmonthdate=2023-01-01, kindid='g'}
weekentity{year='2023', begindate=2023-01-30, enddate=2023-02-05, week=6, weekdesc='第6周(23.01.30~23.02.05)', weekmonth=1, yearmonth='2023-02', yearmonthdate=2023-02-01, kindid='g'}
weekentity{year='2023', begindate=2023-02-06, enddate=2023-02-12, week=7, weekdesc='第7周(23.02.06~23.02.12)', weekmonth=2, yearmonth='2023-02', yearmonthdate=2023-02-01, kindid='g'}
weekentity{year='2023', begindate=2023-02-13, enddate=2023-02-19, week=8, weekdesc='第8周(23.02.13~23.02.19)', weekmonth=3, yearmonth='2023-02', yearmonthdate=2023-02-01, kindid='g'}
weekentity{year='2023', begindate=2023-02-20, enddate=2023-02-26, week=9, weekdesc='第9周(23.02.20~23.02.26)', weekmonth=4, yearmonth='2023-02', yearmonthdate=2023-02-01, kindid='g'}
weekentity{year='2023', begindate=2023-02-27, enddate=2023-03-05, week=10, weekdesc='第10周(23.02.27~23.03.05)', weekmonth=1, yearmonth='2023-03', yearmonthdate=2023-03-01, kindid='g'}
weekentity{year='2023', begindate=2023-03-06, enddate=2023-03-12, week=11, weekdesc='第11周(23.03.06~23.03.12)', weekmonth=2, yearmonth='2023-03', yearmonthdate=2023-03-01, kindid='g'}
weekentity{year='2023', begindate=2023-03-13, enddate=2023-03-19, week=12, weekdesc='第12周(23.03.13~23.03.19)', weekmonth=3, yearmonth='2023-03', yearmonthdate=2023-03-01, kindid='g'}
weekentity{year='2023', begindate=2023-03-20, enddate=2023-03-26, week=13, weekdesc='第13周(23.03.20~23.03.26)', weekmonth=4, yearmonth='2023-03', yearmonthdate=2023-03-01, kindid='g'}
weekentity{year='2023', begindate=2023-03-27, enddate=2023-04-02, week=14, weekdesc='第14周(23.03.27~23.04.02)', weekmonth=1, yearmonth='2023-04', yearmonthdate=2023-04-01, kindid='g'}
weekentity{year='2023', begindate=2023-04-03, enddate=2023-04-09, week=15, weekdesc='第15周(23.04.03~23.04.09)', weekmonth=2, yearmonth='2023-04', yearmonthdate=2023-04-01, kindid='g'}
weekentity{year='2023', begindate=2023-04-10, enddate=2023-04-16, week=16, weekdesc='第16周(23.04.10~23.04.16)', weekmonth=3, yearmonth='2023-04', yearmonthdate=2023-04-01, kindid='g'}
weekentity{year='2023', begindate=2023-04-17, enddate=2023-04-23, week=17, weekdesc='第17周(23.04.17~23.04.23)', weekmonth=4, yearmonth='2023-04', yearmonthdate=2023-04-01, kindid='g'}
weekentity{year='2023', begindate=2023-04-24, enddate=2023-04-30, week=18, weekdesc='第18周(23.04.24~23.04.30)', weekmonth=5, yearmonth='2023-04', yearmonthdate=2023-04-01, kindid='g'}
weekentity{year='2023', begindate=2023-05-01, enddate=2023-05-07, week=19, weekdesc='第19周(23.05.01~23.05.07)', weekmonth=1, yearmonth='2023-05', yearmonthdate=2023-05-01, kindid='g'}
weekentity{year='2023', begindate=2023-05-08, enddate=2023-05-14, week=20, weekdesc='第20周(23.05.08~23.05.14)', weekmonth=2, yearmonth='2023-05', yearmonthdate=2023-05-01, kindid='g'}
weekentity{year='2023', begindate=2023-05-15, enddate=2023-05-21, week=21, weekdesc='第21周(23.05.15~23.05.21)', weekmonth=3, yearmonth='2023-05', yearmonthdate=2023-05-01, kindid='g'}
weekentity{year='2023', begindate=2023-05-22, enddate=2023-05-28, week=22, weekdesc='第22周(23.05.22~23.05.28)', weekmonth=4, yearmonth='2023-05', yearmonthdate=2023-05-01, kindid='g'}
weekentity{year='2023', begindate=2023-05-29, enddate=2023-06-04, week=23, weekdesc='第23周(23.05.29~23.06.04)', weekmonth=1, yearmonth='2023-06', yearmonthdate=2023-06-01, kindid='g'}
weekentity{year='2023', begindate=2023-06-05, enddate=2023-06-11, week=24, weekdesc='第24周(23.06.05~23.06.11)', weekmonth=2, yearmonth='2023-06', yearmonthdate=2023-06-01, kindid='g'}
weekentity{year='2023', begindate=2023-06-12, enddate=2023-06-18, week=25, weekdesc='第25周(23.06.12~23.06.18)', weekmonth=3, yearmonth='2023-06', yearmonthdate=2023-06-01, kindid='g'}
weekentity{year='2023', begindate=2023-06-19, enddate=2023-06-25, week=26, weekdesc='第26周(23.06.19~23.06.25)', weekmonth=4, yearmonth='2023-06', yearmonthdate=2023-06-01, kindid='g'}
weekentity{year='2023', begindate=2023-06-26, enddate=2023-07-02, week=27, weekdesc='第27周(23.06.26~23.07.02)', weekmonth=1, yearmonth='2023-07', yearmonthdate=2023-07-01, kindid='g'}
weekentity{year='2023', begindate=2023-07-03, enddate=2023-07-09, week=28, weekdesc='第28周(23.07.03~23.07.09)', weekmonth=2, yearmonth='2023-07', yearmonthdate=2023-07-01, kindid='g'}
weekentity{year='2023', begindate=2023-07-10, enddate=2023-07-16, week=29, weekdesc='第29周(23.07.10~23.07.16)', weekmonth=3, yearmonth='2023-07', yearmonthdate=2023-07-01, kindid='g'}
weekentity{year='2023', begindate=2023-07-17, enddate=2023-07-23, week=30, weekdesc='第30周(23.07.17~23.07.23)', weekmonth=4, yearmonth='2023-07', yearmonthdate=2023-07-01, kindid='g'}
weekentity{year='2023', begindate=2023-07-24, enddate=2023-07-30, week=31, weekdesc='第31周(23.07.24~23.07.30)', weekmonth=5, yearmonth='2023-07', yearmonthdate=2023-07-01, kindid='g'}
weekentity{year='2023', begindate=2023-07-31, enddate=2023-08-06, week=32, weekdesc='第32周(23.07.31~23.08.06)', weekmonth=1, yearmonth='2023-08', yearmonthdate=2023-08-01, kindid='g'}
weekentity{year='2023', begindate=2023-08-07, enddate=2023-08-13, week=33, weekdesc='第33周(23.08.07~23.08.13)', weekmonth=2, yearmonth='2023-08', yearmonthdate=2023-08-01, kindid='g'}
weekentity{year='2023', begindate=2023-08-14, enddate=2023-08-20, week=34, weekdesc='第34周(23.08.14~23.08.20)', weekmonth=3, yearmonth='2023-08', yearmonthdate=2023-08-01, kindid='g'}
weekentity{year='2023', begindate=2023-08-21, enddate=2023-08-27, week=35, weekdesc='第35周(23.08.21~23.08.27)', weekmonth=4, yearmonth='2023-08', yearmonthdate=2023-08-01, kindid='g'}
weekentity{year='2023', begindate=2023-08-28, enddate=2023-09-03, week=36, weekdesc='第36周(23.08.28~23.09.03)', weekmonth=1, yearmonth='2023-09', yearmonthdate=2023-09-01, kindid='g'}
weekentity{year='2023', begindate=2023-09-04, enddate=2023-09-10, week=37, weekdesc='第37周(23.09.04~23.09.10)', weekmonth=2, yearmonth='2023-09', yearmonthdate=2023-09-01, kindid='g'}
weekentity{year='2023', begindate=2023-09-11, enddate=2023-09-17, week=38, weekdesc='第38周(23.09.11~23.09.17)', weekmonth=3, yearmonth='2023-09', yearmonthdate=2023-09-01, kindid='g'}
weekentity{year='2023', begindate=2023-09-18, enddate=2023-09-24, week=39, weekdesc='第39周(23.09.18~23.09.24)', weekmonth=4, yearmonth='2023-09', yearmonthdate=2023-09-01, kindid='g'}
weekentity{year='2023', begindate=2023-09-25, enddate=2023-10-01, week=40, weekdesc='第40周(23.09.25~23.10.01)', weekmonth=1, yearmonth='2023-10', yearmonthdate=2023-10-01, kindid='g'}
weekentity{year='2023', begindate=2023-10-02, enddate=2023-10-08, week=41, weekdesc='第41周(23.10.02~23.10.08)', weekmonth=2, yearmonth='2023-10', yearmonthdate=2023-10-01, kindid='g'}
weekentity{year='2023', begindate=2023-10-09, enddate=2023-10-15, week=42, weekdesc='第42周(23.10.09~23.10.15)', weekmonth=3, yearmonth='2023-10', yearmonthdate=2023-10-01, kindid='g'}
weekentity{year='2023', begindate=2023-10-16, enddate=2023-10-22, week=43, weekdesc='第43周(23.10.16~23.10.22)', weekmonth=4, yearmonth='2023-10', yearmonthdate=2023-10-01, kindid='g'}
weekentity{year='2023', begindate=2023-10-23, enddate=2023-10-29, week=44, weekdesc='第44周(23.10.23~23.10.29)', weekmonth=5, yearmonth='2023-10', yearmonthdate=2023-10-01, kindid='g'}
weekentity{year='2023', begindate=2023-10-30, enddate=2023-11-05, week=45, weekdesc='第45周(23.10.30~23.11.05)', weekmonth=1, yearmonth='2023-11', yearmonthdate=2023-11-01, kindid='g'}
weekentity{year='2023', begindate=2023-11-06, enddate=2023-11-12, week=46, weekdesc='第46周(23.11.06~23.11.12)', weekmonth=2, yearmonth='2023-11', yearmonthdate=2023-11-01, kindid='g'}
weekentity{year='2023', begindate=2023-11-13, enddate=2023-11-19, week=47, weekdesc='第47周(23.11.13~23.11.19)', weekmonth=3, yearmonth='2023-11', yearmonthdate=2023-11-01, kindid='g'}
weekentity{year='2023', begindate=2023-11-20, enddate=2023-11-26, week=48, weekdesc='第48周(23.11.20~23.11.26)', weekmonth=4, yearmonth='2023-11', yearmonthdate=2023-11-01, kindid='g'}
weekentity{year='2023', begindate=2023-11-27, enddate=2023-12-03, week=49, weekdesc='第49周(23.11.27~23.12.03)', weekmonth=1, yearmonth='2023-12', yearmonthdate=2023-12-01, kindid='g'}
weekentity{year='2023', begindate=2023-12-04, enddate=2023-12-10, week=50, weekdesc='第50周(23.12.04~23.12.10)', weekmonth=2, yearmonth='2023-12', yearmonthdate=2023-12-01, kindid='g'}
weekentity{year='2023', begindate=2023-12-11, enddate=2023-12-17, week=51, weekdesc='第51周(23.12.11~23.12.17)', weekmonth=3, yearmonth='2023-12', yearmonthdate=2023-12-01, kindid='g'}
weekentity{year='2023', begindate=2023-12-18, enddate=2023-12-24, week=52, weekdesc='第52周(23.12.18~23.12.24)', weekmonth=4, yearmonth='2023-12', yearmonthdate=2023-12-01, kindid='g'}
weekentity{year='2023', begindate=2023-12-25, enddate=2023-12-31, week=53, weekdesc='第53周(23.12.25~23.12.31)', weekmonth=5, yearmonth='2023-12', yearmonthdate=2023-12-01, kindid='g'}
weekentity{year='2024', begindate=2024-01-01, enddate=2024-01-07, week=1, weekdesc='第1周(24.01.01~24.01.07)', weekmonth=1, yearmonth='2024-01', yearmonthdate=2024-01-01, kindid='g'}
weekentity{year='2024', begindate=2024-01-08, enddate=2024-01-14, week=2, weekdesc='第2周(24.01.08~24.01.14)', weekmonth=2, yearmonth='2024-01', yearmonthdate=2024-01-01, kindid='g'}
weekentity{year='2024', begindate=2024-01-15, enddate=2024-01-21, week=3, weekdesc='第3周(24.01.15~24.01.21)', weekmonth=3, yearmonth='2024-01', yearmonthdate=2024-01-01, kindid='g'}
weekentity{year='2024', begindate=2024-01-22, enddate=2024-01-28, week=4, weekdesc='第4周(24.01.22~24.01.28)', weekmonth=4, yearmonth='2024-01', yearmonthdate=2024-01-01, kindid='g'}
weekentity{year='2024', begindate=2024-01-29, enddate=2024-02-04, week=5, weekdesc='第5周(24.01.29~24.02.04)', weekmonth=1, yearmonth='2024-02', yearmonthdate=2024-02-01, kindid='g'}
weekentity{year='2024', begindate=2024-02-05, enddate=2024-02-11, week=6, weekdesc='第6周(24.02.05~24.02.11)', weekmonth=2, yearmonth='2024-02', yearmonthdate=2024-02-01, kindid='g'}
weekentity{year='2024', begindate=2024-02-12, enddate=2024-02-18, week=7, weekdesc='第7周(24.02.12~24.02.18)', weekmonth=3, yearmonth='2024-02', yearmonthdate=2024-02-01, kindid='g'}
weekentity{year='2024', begindate=2024-02-19, enddate=2024-02-25, week=8, weekdesc='第8周(24.02.19~24.02.25)', weekmonth=4, yearmonth='2024-02', yearmonthdate=2024-02-01, kindid='g'}
weekentity{year='2024', begindate=2024-02-26, enddate=2024-03-03, week=9, weekdesc='第9周(24.02.26~24.03.03)', weekmonth=1, yearmonth='2024-03', yearmonthdate=2024-03-01, kindid='g'}
weekentity{year='2024', begindate=2024-03-04, enddate=2024-03-10, week=10, weekdesc='第10周(24.03.04~24.03.10)', weekmonth=2, yearmonth='2024-03', yearmonthdate=2024-03-01, kindid='g'}
weekentity{year='2024', begindate=2024-03-11, enddate=2024-03-17, week=11, weekdesc='第11周(24.03.11~24.03.17)', weekmonth=3, yearmonth='2024-03', yearmonthdate=2024-03-01, kindid='g'}
weekentity{year='2024', begindate=2024-03-18, enddate=2024-03-24, week=12, weekdesc='第12周(24.03.18~24.03.24)', weekmonth=4, yearmonth='2024-03', yearmonthdate=2024-03-01, kindid='g'}
weekentity{year='2024', begindate=2024-03-25, enddate=2024-03-31, week=13, weekdesc='第13周(24.03.25~24.03.31)', weekmonth=5, yearmonth='2024-03', yearmonthdate=2024-03-01, kindid='g'}
weekentity{year='2024', begindate=2024-04-01, enddate=2024-04-07, week=14, weekdesc='第14周(24.04.01~24.04.07)', weekmonth=1, yearmonth='2024-04', yearmonthdate=2024-04-01, kindid='g'}
weekentity{year='2024', begindate=2024-04-08, enddate=2024-04-14, week=15, weekdesc='第15周(24.04.08~24.04.14)', weekmonth=2, yearmonth='2024-04', yearmonthdate=2024-04-01, kindid='g'}
weekentity{year='2024', begindate=2024-04-15, enddate=2024-04-21, week=16, weekdesc='第16周(24.04.15~24.04.21)', weekmonth=3, yearmonth='2024-04', yearmonthdate=2024-04-01, kindid='g'}
weekentity{year='2024', begindate=2024-04-22, enddate=2024-04-28, week=17, weekdesc='第17周(24.04.22~24.04.28)', weekmonth=4, yearmonth='2024-04', yearmonthdate=2024-04-01, kindid='g'}
weekentity{year='2024', begindate=2024-04-29, enddate=2024-05-05, week=18, weekdesc='第18周(24.04.29~24.05.05)', weekmonth=1, yearmonth='2024-05', yearmonthdate=2024-05-01, kindid='g'}
weekentity{year='2024', begindate=2024-05-06, enddate=2024-05-12, week=19, weekdesc='第19周(24.05.06~24.05.12)', weekmonth=2, yearmonth='2024-05', yearmonthdate=2024-05-01, kindid='g'}
weekentity{year='2024', begindate=2024-05-13, enddate=2024-05-19, week=20, weekdesc='第20周(24.05.13~24.05.19)', weekmonth=3, yearmonth='2024-05', yearmonthdate=2024-05-01, kindid='g'}
weekentity{year='2024', begindate=2024-05-20, enddate=2024-05-26, week=21, weekdesc='第21周(24.05.20~24.05.26)', weekmonth=4, yearmonth='2024-05', yearmonthdate=2024-05-01, kindid='g'}
weekentity{year='2024', begindate=2024-05-27, enddate=2024-06-02, week=22, weekdesc='第22周(24.05.27~24.06.02)', weekmonth=1, yearmonth='2024-06', yearmonthdate=2024-06-01, kindid='g'}
weekentity{year='2024', begindate=2024-06-03, enddate=2024-06-09, week=23, weekdesc='第23周(24.06.03~24.06.09)', weekmonth=2, yearmonth='2024-06', yearmonthdate=2024-06-01, kindid='g'}
weekentity{year='2024', begindate=2024-06-10, enddate=2024-06-16, week=24, weekdesc='第24周(24.06.10~24.06.16)', weekmonth=3, yearmonth='2024-06', yearmonthdate=2024-06-01, kindid='g'}
weekentity{year='2024', begindate=2024-06-17, enddate=2024-06-23, week=25, weekdesc='第25周(24.06.17~24.06.23)', weekmonth=4, yearmonth='2024-06', yearmonthdate=2024-06-01, kindid='g'}
weekentity{year='2024', begindate=2024-06-24, enddate=2024-06-30, week=26, weekdesc='第26周(24.06.24~24.06.30)', weekmonth=5, yearmonth='2024-06', yearmonthdate=2024-06-01, kindid='g'}
weekentity{year='2024', begindate=2024-07-01, enddate=2024-07-07, week=27, weekdesc='第27周(24.07.01~24.07.07)', weekmonth=1, yearmonth='2024-07', yearmonthdate=2024-07-01, kindid='g'}
weekentity{year='2024', begindate=2024-07-08, enddate=2024-07-14, week=28, weekdesc='第28周(24.07.08~24.07.14)', weekmonth=2, yearmonth='2024-07', yearmonthdate=2024-07-01, kindid='g'}
weekentity{year='2024', begindate=2024-07-15, enddate=2024-07-21, week=29, weekdesc='第29周(24.07.15~24.07.21)', weekmonth=3, yearmonth='2024-07', yearmonthdate=2024-07-01, kindid='g'}
weekentity{year='2024', begindate=2024-07-22, enddate=2024-07-28, week=30, weekdesc='第30周(24.07.22~24.07.28)', weekmonth=4, yearmonth='2024-07', yearmonthdate=2024-07-01, kindid='g'}
weekentity{year='2024', begindate=2024-07-29, enddate=2024-08-04, week=31, weekdesc='第31周(24.07.29~24.08.04)', weekmonth=1, yearmonth='2024-08', yearmonthdate=2024-08-01, kindid='g'}
weekentity{year='2024', begindate=2024-08-05, enddate=2024-08-11, week=32, weekdesc='第32周(24.08.05~24.08.11)', weekmonth=2, yearmonth='2024-08', yearmonthdate=2024-08-01, kindid='g'}
weekentity{year='2024', begindate=2024-08-12, enddate=2024-08-18, week=33, weekdesc='第33周(24.08.12~24.08.18)', weekmonth=3, yearmonth='2024-08', yearmonthdate=2024-08-01, kindid='g'}
weekentity{year='2024', begindate=2024-08-19, enddate=2024-08-25, week=34, weekdesc='第34周(24.08.19~24.08.25)', weekmonth=4, yearmonth='2024-08', yearmonthdate=2024-08-01, kindid='g'}
weekentity{year='2024', begindate=2024-08-26, enddate=2024-09-01, week=35, weekdesc='第35周(24.08.26~24.09.01)', weekmonth=1, yearmonth='2024-09', yearmonthdate=2024-09-01, kindid='g'}
weekentity{year='2024', begindate=2024-09-02, enddate=2024-09-08, week=36, weekdesc='第36周(24.09.02~24.09.08)', weekmonth=2, yearmonth='2024-09', yearmonthdate=2024-09-01, kindid='g'}
weekentity{year='2024', begindate=2024-09-09, enddate=2024-09-15, week=37, weekdesc='第37周(24.09.09~24.09.15)', weekmonth=3, yearmonth='2024-09', yearmonthdate=2024-09-01, kindid='g'}
weekentity{year='2024', begindate=2024-09-16, enddate=2024-09-22, week=38, weekdesc='第38周(24.09.16~24.09.22)', weekmonth=4, yearmonth='2024-09', yearmonthdate=2024-09-01, kindid='g'}
weekentity{year='2024', begindate=2024-09-23, enddate=2024-09-29, week=39, weekdesc='第39周(24.09.23~24.09.29)', weekmonth=5, yearmonth='2024-09', yearmonthdate=2024-09-01, kindid='g'}
weekentity{year='2024', begindate=2024-09-30, enddate=2024-10-06, week=40, weekdesc='第40周(24.09.30~24.10.06)', weekmonth=1, yearmonth='2024-10', yearmonthdate=2024-10-01, kindid='g'}
weekentity{year='2024', begindate=2024-10-07, enddate=2024-10-13, week=41, weekdesc='第41周(24.10.07~24.10.13)', weekmonth=2, yearmonth='2024-10', yearmonthdate=2024-10-01, kindid='g'}
weekentity{year='2024', begindate=2024-10-14, enddate=2024-10-20, week=42, weekdesc='第42周(24.10.14~24.10.20)', weekmonth=3, yearmonth='2024-10', yearmonthdate=2024-10-01, kindid='g'}
weekentity{year='2024', begindate=2024-10-21, enddate=2024-10-27, week=43, weekdesc='第43周(24.10.21~24.10.27)', weekmonth=4, yearmonth='2024-10', yearmonthdate=2024-10-01, kindid='g'}
weekentity{year='2024', begindate=2024-10-28, enddate=2024-11-03, week=44, weekdesc='第44周(24.10.28~24.11.03)', weekmonth=1, yearmonth='2024-11', yearmonthdate=2024-11-01, kindid='g'}
weekentity{year='2024', begindate=2024-11-04, enddate=2024-11-10, week=45, weekdesc='第45周(24.11.04~24.11.10)', weekmonth=2, yearmonth='2024-11', yearmonthdate=2024-11-01, kindid='g'}
weekentity{year='2024', begindate=2024-11-11, enddate=2024-11-17, week=46, weekdesc='第46周(24.11.11~24.11.17)', weekmonth=3, yearmonth='2024-11', yearmonthdate=2024-11-01, kindid='g'}
weekentity{year='2024', begindate=2024-11-18, enddate=2024-11-24, week=47, weekdesc='第47周(24.11.18~24.11.24)', weekmonth=4, yearmonth='2024-11', yearmonthdate=2024-11-01, kindid='g'}
weekentity{year='2024', begindate=2024-11-25, enddate=2024-12-01, week=48, weekdesc='第48周(24.11.25~24.12.01)', weekmonth=1, yearmonth='2024-12', yearmonthdate=2024-12-01, kindid='g'}
weekentity{year='2024', begindate=2024-12-02, enddate=2024-12-08, week=49, weekdesc='第49周(24.12.02~24.12.08)', weekmonth=2, yearmonth='2024-12', yearmonthdate=2024-12-01, kindid='g'}
weekentity{year='2024', begindate=2024-12-09, enddate=2024-12-15, week=50, weekdesc='第50周(24.12.09~24.12.15)', weekmonth=3, yearmonth='2024-12', yearmonthdate=2024-12-01, kindid='g'}
weekentity{year='2024', begindate=2024-12-16, enddate=2024-12-22, week=51, weekdesc='第51周(24.12.16~24.12.22)', weekmonth=4, yearmonth='2024-12', yearmonthdate=2024-12-01, kindid='g'}
weekentity{year='2024', begindate=2024-12-23, enddate=2024-12-29, week=52, weekdesc='第52周(24.12.23~24.12.29)', weekmonth=5, yearmonth='2024-12', yearmonthdate=2024-12-01, kindid='g'}

5.数据保存

最后,保存list<weekentity> weeks到数据库即可。

到此这篇关于基于java实现根据周次生成数据的工具类的文章就介绍到这了,更多相关java生成周次数据内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com