οnclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d'})"
/**
* 获取星期名称
*
* @param date
* 日期
* @return
*/
public static String getDayweek(Date date) {
String[] weeks = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int dayinweek = cal.get(Calendar.DAY_OF_WEEK) - 1;
return weeks[dayinweek];
}
/**
* 获取当前日期起始周(星期一)
*
* @param date
* 日期
* @return
*/
public static Date getWeekStart(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int day = cal.get(Calendar.DAY_OF_WEEK) - 1;
cal.add(Calendar.DATE, -day + 1);
return cal.getTime();
}
/**
* 获取当前日期周末(星期日)
*
* @param date
* 日期
* @return
*/
public static Date getWeekEnd(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int day = cal.get(Calendar.DAY_OF_WEEK) - 1;
cal.add(Calendar.DATE, 6 - day + 1);
return cal.getTime();
}
/**
* 日期转换为字符串
*
* @param date
* @return
*/
public static String changeToString(Date date) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date2 = df.format(date);
return date2;
}
/**
* 日期转换为字符串(时间+日期)
* @param date
* @return
*/
public static String changeDateTimeToString(Date date) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String date2 = df.format(date);
return date2;
}
/**
* 字符串转换为日期
* @param date
* @return
*/
public static Date changeToDatetime(String datetime) throws ParseException {
String strFormat = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
Date date1 = sdf.parse(datetime);
return date1;
}
/**
* 字符串转换为日期
* @param date
* @return
*/
public static Date changeToDate(String datetime) throws ParseException {
String strFormat = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
Date date1 = sdf.parse(datetime);
return date1;
}
/**
* 日期转换为星期
* @param date
* @return
*/
public static String changeToWeek(Date date){
String[] weeks = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int dayinweek = cal.get(Calendar.DAY_OF_WEEK) - 1;
return weeks[dayinweek];
}
/**
* 日期转换为星期
* @param date
* @return
*/
public static Date changeToAddDay(int i){
Calendar c=Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, i);
Date date = c.getTime();
return date;
}