gpt4 book ai didi

Java - 如何计算每周的第一天和最后一天

转载 作者:太空狗 更新时间:2023-10-29 22:41:52 25 4
gpt4 key购买 nike

我正在尝试创建如下所示的每周日历:http://dhtmlx.com/docs/products/dhtmlxScheduler/sample_basic.html

如何计算每周日期?比如本周是:

Monday - Sunday
7 June, 8 June, 9 June, 10 June, 11 June, 12 June, 13 June

最佳答案

我猜这就是你想要的:

// Get calendar set to current date and time
Calendar c = Calendar.getInstance();

// Set the calendar to monday of the current week
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

// Print dates of the current week starting on Monday
DateFormat df = new SimpleDateFormat("EEE dd/MM/yyyy");
for (int i = 0; i < 7; i++) {
System.out.println(df.format(c.getTime()));
c.add(Calendar.DATE, 1);
}

关于Java - 如何计算每周的第一天和最后一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3023267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com