根据指定的日期字符串获取星期几

	/**
	 * 
	 * 根据指定的日期字符串获取星期几
	 * 
* * @param strDate 指定的日期字符串(yyyy-MM-dd 或 yyyy/MM/dd) * @return week * 星期几(MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY) */ public static String getWeekByDateStr(String strDate) { int year = Integer.parseInt(strDate.substring(0, 4)); int month = Integer.parseInt(strDate.substring(5, 7)); int day = Integer.parseInt(strDate.substring(8, 10)); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month - 1); c.set(Calendar.DAY_OF_MONTH, day); String week = ""; int weekIndex = c.get(Calendar.DAY_OF_WEEK); switch (weekIndex) { case 1: week = "SUNDAY"; break; case 2: week = "MONDAY"; break; case 3: week = "TUESDAY"; break; case 4: week = "WEDNESDAY"; break; case 5: week = "THURSDAY"; break; case 6: week = "FRIDAY"; break; case 7: week = "SATURDAY"; break; } return week; }

你可能感兴趣的:(Java)