第一种: 日历工具类
package com.baidu.base.util;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
*
* @Title: CalendarUtil
* @Description: 日历工具类
*/
public class CalendarUtil {
/**
*
* @Description 获得指定日期工作周的指定星期几的日期
* @Title getDateByWeekToDate
* @param date
* @param week
* @return
*/
public static Date getDateByWeekToDate(Date date, int week) {
if (week <= 0) {
return date;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_WEEK, week);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return calendar.getTime();
}
/**
* @Description 得到按当前日期往前推一个月格式化时间格式为 00:00:00
* @Title getUpperMonthTheToDay