`

Java获取某一时间为当年/月的第几周

    博客分类:
  • Java
阅读更多
/**
	 * 根据日期字符串判断当月第几周
	 * 
	 * @param date
	 * @return
	 * @throws Exception
	 */
	public static int getWeekOfMonth(String date) throws Exception {
		// 将字符串格式化
		Date d = convertToDate(date);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(d);

		// 第几周
		return calendar.get(Calendar.WEEK_OF_YEAR);
	}

	/**
	 * 根据日期字符串判断当年第几周
	 * 
	 * @param date
	 * @return
	 * @throws Exception
	 */
	public static int getWeekOfYear(String date) throws Exception {
		// 将字符串格式化
		Date d = convertToDate(date);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(d);

		// 第几周
		return calendar.get(Calendar.WEEK_OF_YEAR);
	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics