gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:35:15 26 4
gpt4 key购买 nike

我在获取时遇到问题 WEEK_OF_YEAR从日历对象。

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);

最佳答案

WEEK_OF_YEAR正如您在 this javadoc 中看到的那样,定义取决于语言环境:

Values calculated for the WEEK_OF_YEAR field range from 1 to 53. The first week of a calendar year is the earliest seven day period starting on getFirstDayOfWeek() that contains at least getMinimalDaysInFirstWeek() days from that year. It thus depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year (exclusive) are numbered sequentially from 2 to 52 or 53 (except for year(s) involved in the Julian-Gregorian transition).



也看看 this question或在 Wiki - ISO clock查看周差。

关于java - 从日历对象中获取 WEEK_OF_YEAR 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12037825/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com