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?(Java Calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY),它会向后滚动,向前滚动还是未知?)
本文介绍了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_OF_MONTH).来自文档:

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

当设置或获取WEEK_OF_MONTH 或 WEEK_OF_YEAR 字段,日历必须确定第一周作为参考的月份或年份观点.一个月的第一周或年份被定义为最早的七个日期间开始于getFirstDayOfWeek() 并包含在最少 getMinimalDaysInFirstWeek() 天那个月或那个年.周数..., -1, 0 在第一周之前;第 2 周、第 3 周、... 跟随它.请注意,标准化编号get() 返回的可能不同.例如,特定的日历子类可以指定前一周一年的第 1 周作为第 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),它会向后滚动,向前滚动还是未知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Month is not printed from a date - Java DateFormat(月份不是从日期打印的 - Java DateFormat)
java get week of year for given a date(java获取给定日期的一年中的一周)
Get the number of days, weeks, and months, since Epoch in Java(获取自 Java 中的 Epoch 以来的天数、周数和月数)
Is there a good way to get the date of the coming Wednesday?(有什么好方法可以得到即将到来的星期三的日期吗?)
Calendar view for Android GingerBread and before (APIlt;11)(Android GingerBread 及之前的日历视图 (API11))
How to save and retrieve Date in SharedPreferences(如何在 SharedPreferences 中保存和检索日期)