public class DateUtil {
private static final String[] weeks = { "星期�一", "星期�二", "星期�三", "星期�四", "星期五",
"星期�六", "星期�七" };
// 日期格式1
public static final String format1 = "yyyy-MM-dd";
// 日期格式2
public static final String format2 = "yyyy-MM-dd HH:mm:ss";
// 日期格式3
public static final String format3 = "yyyyMMdd";
// 日期格式3
public static final String format4 = "yyyyMMddHHmmssSSS";
/**
* 根据参数pattern格式化日期
* @param date
* @param pattern
* @return String
*/
public static String formatDate(Date date, String pattern) {
SimpleDateFormat frm = new SimpleDateFormat(pattern);
return frm.format(date);
}
/**
* 取得星期几
* @param date
* @return String
*/
public static String getWeekDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return weeks[calendar.get(Calendar.DAY_OF_WEEK) - 1];
}
/**
* 取得今天,格式如XXXX年XX月XX�日 今天是星期几
* @return String
*/
public static String getNowDay() {
Date date = new Date();
String nowdate = formatDate(new Date(), format1);
String[] dateArray = nowdate.split("-");
StringBuffer temp = new StringBuffer("");
temp.append(dateArray[0]).append("�?").append(dateArray[1]).append("�?")
.append(dateArray[2]).append("�?").append(" 今天�?").append(getWeekDay(date));
return temp.toString();
}
/**
* 取得今天
* @return String
*/
public static String getNowDay(String format) {
return formatDate(new Date(),format);
}