Here you can find the source of getYearWeek(int year, int week)
Parameter | Description |
---|---|
year | a parameter |
week | a parameter |
public static String[] getYearWeek(int year, int week)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; public class Main { public static String[] getYearWeek(int year, int week) { String result = ""; Calendar cal = new GregorianCalendar(Locale.CHINESE); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); Date day = new Date(year - 1900, 0, 1); for (int i = 0; i < 366; i++) { cal.setTime(day);// www. j ava 2 s . c o m if (cal.get(Calendar.DAY_OF_WEEK) == week) { if (day.getYear() == year - 1900) result += "/" + formatter.format(day); } day.setDate(day.getDate() + 1); cal.setTime(day); } return (result.split("/")); } public static String getDate() { Calendar calendar = Calendar.getInstance(); String strDate = "" + calendar.get(Calendar.DATE); String strMonth = "" + (calendar.get(Calendar.MONTH) + 1); if ((calendar.get(Calendar.MONTH) + 1) > 12) { strMonth = "01"; } String strYear = "" + calendar.get(Calendar.YEAR); if (strDate.length() < 2) { strDate = "0" + strDate; } if (strMonth.length() < 2) { strMonth = "0" + strMonth; } String curDate = strYear + strMonth + strDate; return curDate; } public static String getDate(String strYYYYMM) { String strDate = null; if (strYYYYMM.substring(4).equals("01") || strYYYYMM.substring(4).equals("03") || strYYYYMM.substring(4).equals("05") || strYYYYMM.substring(4).equals("07") || strYYYYMM.substring(4).equals("08") || strYYYYMM.substring(4).equals("10") || strYYYYMM.substring(4).equals("12")) { strDate = strYYYYMM + "31"; } else if (strYYYYMM.substring(4).equals("04") || strYYYYMM.substring(4).equals("06") || strYYYYMM.substring(4).equals("09") || strYYYYMM.substring(4).equals("11")) { strDate = strYYYYMM + "30"; } else { if (isLeapYear(strYYYYMM.substring(0, 4))) { strDate = strYYYYMM + "29"; } else { strDate = strYYYYMM + "28"; } } return strDate; } public static boolean isLeapYear(String strYYYY) { boolean bLeap = false; Calendar cal = Calendar.getInstance(); bLeap = ((GregorianCalendar) cal).isLeapYear(Integer.parseInt(strYYYY)); return bLeap; } }