编程语言
首页 > 编程语言> > java – 日历错误的一周

java – 日历错误的一周

作者:互联网

我有一个日历对象如下所示,代表2014年8月8日.这是星期五.所以myCal.get(Calendar.DAY_OF_WEEK)应该是6.但它给出2.为什么?

java.util.GregorianCalendar[time=1410177767000,areFieldsSet=true,lenient=true,zone=Asia/Calcutta,firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=8,WEEK_OF_YEAR=37,WEEK_OF_MONTH=2,DAY_OF_MONTH=8,DAY_OF_YEAR=251,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=32,SECOND=47,MILLISECOND=0,ZONE_OFFSET=19800000,DST_OFFSET=0]

解决方法:

I have a calendar object as below that represents 08 Aug 2014.

它不是:MONTH = 8是九月,而不是八月(月份编号从零开始).

您可以通过在输出中注明DAY_OF_YEAR = 251来验证自己. The 251st day of a non-leap year is 8 September.

检查时间戳的另一种方法是将1410177767000粘贴到http://www.epochconverter.com/

标签:java,date,calendar,dayofweek
来源: https://codeday.me/bug/20190713/1454022.html