不确定什么get(Calendar.DAY_OF_WEEK)返回 [英] Unsure what get(Calendar.DAY_OF_WEEK) returns
问题描述
我的问题可以通过以下场景轻松创建:
//创建一个gregorian日历对象,时间为2012年6月4日下午10:30
日历calendar = new GregorianCalendar(2012,6,4,22,30);
//当我打印出这些:
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
System.out.println(calendar.get(Calendar.MINUTE));
System.out.println(calendar.get(Calendar.HOUR));
System.out.println(calendar.get(Calendar.DATE));
System.out.println(calendar.get(Calendar.MONTH));
System.out.println(calendar.get(Calendar.YEAR));
//输出显示为:
4
30
10
4
6
2012
//这样做calendar.get(Calendar.DAY_OF_WEEK)== calendar.get(Calendar.DATE)???
只是为了让每个人都清楚2012年6月4日是星期一,所以不应该日历。 get(Calendar.DAY_OF_WEEK)在一周的第一天返回0?
感谢您的帮助和关注,请验证您的来源
user1442080
是基于0。因此,6月是第5个月。
您实际创建了一个表示7月4日的对象,这恰好是星期三,
My problem can be easily created by the scenario below:
//create a gregorian calendar object that set the date and time as 4th June 2012 at 10:30PM
Calendar calendar = new GregorianCalendar(2012, 6, 4, 22, 30);
//when I print out these:
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
System.out.println(calendar.get(Calendar.MINUTE));
System.out.println(calendar.get(Calendar.HOUR));
System.out.println(calendar.get(Calendar.DATE));
System.out.println(calendar.get(Calendar.MONTH));
System.out.println(calendar.get(Calendar.YEAR));
//output reads as:
4
30
10
4
6
2012
//so does calendar.get(Calendar.DAY_OF_WEEK) == calendar.get(Calendar.DATE) ???
Just so that everyone is clear the 4th of June 2012 is a Monday, so shouldn't calendar.get(Calendar.DAY_OF_WEEK) return 0 as part of the first day of the week?
Thank for your all your help and concerns, please also verify the source that you are referring to.
user1442080
The month in java Calendar classes is 0-based. So June is month number 5.
You actually created an object representing July 4th, which happens to be a Wednesday, i.e. the fourht day of that week.
这篇关于不确定什么get(Calendar.DAY_OF_WEEK)返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!