首页 > 其他 > 详细

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

时间:2014-01-21 00:17:10      阅读:485      评论:0      收藏:0      [点我收藏+]
	/**
	 * <pre>
	 * 根据指定的日期字符串获取星期几
	 * </pre>
	 * 
	 * @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;
	}

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

原文:http://blog.csdn.net/lwcumt/article/details/18410345

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!