Java Utililty Methods Week of Year

List of utility methods to do Week of Year

Description

The list of methods to do Week of Year are organized into topic(s).

Method

intgetWeekOfPreYearWeek(int year, int week)
get Week Of Pre Year Week
return week == 1 ? getMaxWeekNumOfYear(year) : week - 1;
StringgetWeekOfYear()
get Week Of Year
String num = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR) + "";
return num.length() == 1 ? "0" + num : num;
intgetWeekOfYear(String year, String month, String day)
get Week Of Year
Calendar cal = new GregorianCalendar();
cal.clear();
cal.set(new Integer(year).intValue(), new Integer(month).intValue() - 1, new Integer(day).intValue());
return cal.get(Calendar.WEEK_OF_YEAR);
intgetWeekOfYearByDay(String year, String month, String day)
get Week Of Year By Day
Calendar calendar = Calendar.getInstance(Locale.UK);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(4);
calendar.set(Calendar.YEAR, Integer.parseInt(year));
calendar.set(Calendar.MONTH, Integer.parseInt(month) - 1);
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
long milltimes = calendar.getTimeInMillis();
calendar.setTimeInMillis(milltimes);
...
intgetWeekOfYearFromTimestamp(long ms)
get Week Of Year From Timestamp
if (ms < 0)
    throw new NumberFormatException("argument must be positive");
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
cal.setTimeInMillis(ms);
return cal.get(Calendar.WEEK_OF_YEAR);