Java - How to calculate the first and last day of each week

前端 未结 11 1026
难免孤独
难免孤独 2020-12-05 05:16

I\'m trying to create a weekly calendar that looks like this: http://dhtmlx.com/docs/products/dhtmlxScheduler/sample_basic.html

How can I calculate every week date?

11条回答
  •  孤城傲影
    2020-12-05 06:06

    You can build up on this: The following code prints the first and last dates of each week for 15 weeks from now.

    Calendar c = Calendar.getInstance();
    c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    for(int i=0; i<15; i++)
    {
        System.out.print("Start Date : " + c.getTime() + ", ");
        c.add(Calendar.DAY_OF_WEEK, 6);
        System.out.println("End Date : " + c.getTime());
        c.add(Calendar.DAY_OF_WEEK, 1);
    }
    

提交回复
热议问题