1.根据日期获取星期
/** * @name: getWeekOfDate() * @param: date * @return: week */ public String getWeekOfDate(Date date){ String[] arrayWeek={"Sun","Mon","Tues","Wed","Thur","Fir","Sat"}; Calendar cal = Calendar.getInstance(); cal.setTime(date); int w = cal.get(Calendar.DAY_OF_WEEK); return arrayWeek[w-1]; }
2.将字符类型格式化为规定格式的日期类型
/** * @name: formatDate() * @param: dateStr * @return: date */ public Date formatDate(String dateStr) throws ParseException{ SimpleDateFormat df =new SimpleDateFormat("yyyy-MM-dd"); Date date = df.parse(dateStr); return date; }