Java 从日历对象获取年中的周时,我遇到问题
从calendar对象获取年中的周时,我遇到问题Java 从日历对象获取年中的周时,我遇到问题,java,calendar,Java,Calendar,从calendar对象获取年中的周时,我遇到问题 by passing date '31-Dec-2014': calendar1.get(Calendar.WEEK_OF_YEAR) - return 1 by passing date '31-Dec-2015' calendar1.get(Calendar.WEEK_OF_YEAR) - return 53 by passing date '31-Dec-2016' calendar1.get(Calendar.WE
by passing date '31-Dec-2014':
calendar1.get(Calendar.WEEK_OF_YEAR) - return 1
by passing date '31-Dec-2015'
calendar1.get(Calendar.WEEK_OF_YEAR) - return 53
by passing date '31-Dec-2016'
calendar1.get(Calendar.WEEK_OF_YEAR) - return 52
by passing date '31-Dec-2017'
calendar1.get(Calendar.WEEK_OF_YEAR) - return 52
by passing date '31-Dec-2018'
calendar1.get(Calendar.WEEK_OF_YEAR) - return 1
每次它都返回不同的值。你能帮我解决这个问题吗
代码如下
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime('31-Dec-2012');
calendar1.set(Calendar.HOUR_OF_DAY, 0);
calendar1.setFirstDayOfWeek(Calendar.MONDAY);
一年中的一周
定义取决于区域设置,如图所示:
“年中的周”字段的计算值范围为1到53。日历年的第一周是从getFirstDayOfWeek()开始的最早的七天周期,其中至少包含从该年开始的getMinimalDaysInFirstWeek()天。因此,它取决于getMinimalDaysInFirstWeek()、getFirstDayOfWeek()和1月1日的星期几的值。从一年的第1周到下一年的第1周(不包括)之间的周从2到52或53依次编号(朱利安-格列高利过渡所涉及的年份除外)
还可以查看或查看一周的差异。这是一个重复的问题,但长话短说
Calendar c = Calendar.getInstance();
c.setMinimalDaysInFirstWeek(7);//anything more than 1 will work in this year
DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
c.setTime( sdf.parse("31/12/2010"));
System.out.println( c.get( Calendar.WEEK_OF_YEAR ) );
2012年12月31日申报表53