buildDate(String year,String month , String day) throws Exception {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
return sdf.parse(year+"-"+String.format("%02d",Integer.parseInt(month))+"-"+String.format("%02d",Integer.parseInt(day))) ;
}
获得星期几 星期日 1 星期一 2 …… 星期六 7
int getDayW(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_WEEK);
}
int getLastDayOfMonth(Date date)
{
Date MonthFirst=DateUtil.parseDate(DateUtil.format(date,"yyyyMM") + "01","yyyyMMdd");
Date NextMonthFirst=DateAddMonths(MonthFirst,1);
return getDayM(DateAddDays(NextMonthFirst ,-1));
}
去掉时间,只留日期,也就是当日的00:00
Date dayZeroTime(Date day) {
return DateUtil.parseDate(DateUtil.format(day,"yyyyMMdd"),"yyyyMMdd");
}
int getDaysBetween (Date d1,Date d2) {
Calendar c1=Calendar.getInstance();
c1.setTime(d1);
Calendar c2=Calendar.getInstance();
c2.setTime(d2);
return getDaysBetween(c1,c2);
一个时间,多少小时以后/以前
Date DateAddHours(Date oriDate,int hour) {
Calendar c= Calendar.getInstance();
c.setTime(oriDate);
c.add(Calendar.HOUR,hour);
return c.getTime();
}
多少分以后/以前
Date DateAddMinutes(Date oriDate,int m) {
Calendar c= Calendar.getInstance();
c.setTime(oriDate);
c.add(Calendar.MINUTE,m);
return c.getTime();
}
Date DateAddDays(Date oriDate,int m) {
Calendar c= Calendar.getInstance();
c.setTime(oriDate);
c.add(Calendar.DAY_OF_MONTH,m);
return c.getTime();
}
Date DateAddMonths(Date oriDate,int m) {
Calendar c= Calendar.getInstance();
c.setTime(oriDate);
c.add(Calendar.MONTH,m);
return c.getTime();
}