Java Calendar.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY),它会向后滚动,向前滚动还是未知? [英] Java Calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY), will it roll backwards, forwards or unknown?

查看:1500
本文介绍了Java Calendar.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY),它会向后滚动,向前滚动还是未知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Suppose the following code is executed on the 22nd of August 2009 (a Saturday)

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

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

c.get(Calendar.DAY_OF_MONTH) will return 23. I'm interested in the conditions is would return 14 (last Sunday, rather than the next Sunday).

有与方向相关的任何规则将在设置 DAY_OF_WEEK 时滚动 DAY_OF_MONTH / YEAR

Are there any rules associated with the direction Calendar will roll the DAY_OF_MONTH/YEAR when DAY_OF_WEEK is set? If so what are they?

推荐答案

它应该始终保持不变 WEEK_OF_MONTH http://java.sun。 com / j2se / 1.4.2 / docs / api / java / util / Calendar.html#WEEK%5FOF%5FMONTH )。从文档:

It should always keep the same WEEK_OF_MONTH (http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#WEEK%5FOF%5FMONTH). From the documentation:


设置或获取
WEEK_OF_MONTH或WEEK_OF_YEAR字段时,
日历必须确定第一周
的月或年作为参考
点。一个月的第一周或
年被定义为从
getFirstDayOfWeek()开始的最早的七个
日期,并且包含
至少getMinimalDaysInFirstWeek()天
那个月或年。周编号为
...,-1,0在第一周之前;
周编号2,3,...跟着它。
请注意,get()返回的标准化编号
可能不同。
例如,特定日历
子类可以指定一年中的
前一周作为上一年
的第n周。

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),它会向后滚动,向前滚动还是未知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆