JAVA 非常实用的日期工具类
import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class DateUtils extends org.apache.commons.lang.time.DateUtils {/** * 格式化 * * @param date * @param format * @return String */public static String parseDate(Date date, String parsePatterns) {SimpleDateFormat sdf = new SimpleDateFormat(parsePatterns);return sdf.format(date);}/** * 默认格式化(yyyy-MM-dd HH:mm:ss) * * @param date * @return String */public static String parseDate(Date date) {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");return sdf.format(date);}/** * 默认格式化(yyyy-MM-dd HH:mm:ss) * * @param str * @return * @throws ParseException */public static Date parseDate(String str) throws ParseException {return DateUtils.parseDate(str, new String[] { "yyyy-MM-dd HH:mm:ss" });}/** * 得到某个月的第一天 * * @param date * @return Date */public static Date getFirstDayOfMonth(Date date) throws ParseException {String strdate = DateUtils.parseDate(date, "yyyy-MM-01 00:00:00");return DateUtils.parseDate(strdate);}public static int getDayOfWeek() throws ParseException {Calendar c = Calendar.getInstance();int dayForWeek = 0;if(c.get(Calendar.DAY_OF_WEEK) == 1){ dayForWeek = 7; }else{ dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1; }return dayForWeek;}public static String getWeekOfDate(Date date,int tag) { String[] weekDaysName = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; String[] weekDaysCode = { "7", "1", "2", "3", "4", "5", "6" }; Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int intWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; if( tag == 0 ){ return weekDaysName[intWeek]; }else{ return weekDaysCode[intWeek]; }} }?