java. util. Calendar WEEK_ OF_ Year provides 1 for 365 and 366 days
•
Java
An attempt was made to find the week for the given date
Question: December 29, 2012 = week 52 December 30, 2012 = week 1 December 30, 2013 = week 52 December 31, 2013 = week 1
When current year share = 365 or 366, it provides one week of the year to 1 It seems that something has happened How to solve this problem?
import java.util.Calendar;
import java.util.GregorianCalendar;
public class cal2{
public static void main (String[] args) {
Calendar mycal = GregorianCalendar.getInstance();
mycal.setLenient(false);
int year = 2012;
int month = 11; //0=Jan,11=Dec
int date = 29;
mycal.set(year,1);
mycal.setFirstDayOfWeek(mycal.get(mycal.DAY_OF_WEEK));
mycal.set(year,month,date);
System.out.println("\n>>>>>>>>WEEK :"+mycal.get(mycal.WEEK_OF_YEAR));
// System.out.println("\nDATE :"+mycal);
}
}
Solution
See here from docs
First week
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
