gpt4 book ai didi

Java Calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY),它会向后滚动,向前滚动还是未知?

转载 作者:IT老高 更新时间:2023-10-28 21:15:50 28 4
gpt4 key购买 nike

假设以下代码在 2009 年 8 月 22 日(星期六)执行

   Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

c.get(Calendar.DAY_OF_MONTH) 将返回 23。我感兴趣的条件是返回 14(上周日,而不是下周日)。

当设置 DAY_OF_WEEK 时,是否有任何与日历滚动 DAY_OF_MONTH/YEAR 的方向相关的规则?如果有,它们是什么?

最佳答案

它应该始终保持相同的 WEEK_OF_MONTH (http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#WEEK_OF_MONTH)。来自文档:

When setting or getting the WEEK_OF_MONTH or WEEK_OF_YEAR fields, Calendar must determine the first week of the month or year as a reference point. The first week of a month or year is defined as the earliest seven day period beginning on getFirstDayOfWeek() and containing at least getMinimalDaysInFirstWeek() days of that month or year. Weeks numbered ..., -1, 0 precede the first week; weeks numbered 2, 3,... follow it. Note that the normalized numbering returned by get() may be different. For example, a specific Calendar subclass may designate the week before week 1 of a year as week n of the previous year.

关于Java Calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY),它会向后滚动,向前滚动还是未知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1319473/

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