本文介绍了从日历对象获取WEEK_OF_YEAR时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从日历对象中获取 WEEK_OF_YEAR 时出现问题。

I am getting issue while fetching WEEK_OF_YEAR from calendar object.

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

每次返回不同的值。您可以帮我解决这个问题。

Every time it returns different value . Could you please help me to solve this issue.

代码如下。

  Calendar calendar1 = Calendar.getInstance();
  calendar1.setTime('31-Dec-2012');
  calendar1.set(Calendar.HOUR_OF_DAY, 0);
  calendar1.setFirstDayOfWeek(Calendar.MONDAY);


推荐答案

WEEK_OF_YEAR 定义是Locale依赖,您可以在:

WEEK_OF_YEAR definition is Locale dependent as you can see in this javadoc :

还可以查看或在查看周的差异。

also have a look at this question or at Wiki - ISO clock to see the week difference.

这篇关于从日历对象获取WEEK_OF_YEAR时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:10