public classDateUtil {public staticDate getDate(Date date){
Date dt= null;
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
calendar.add(Calendar.DAY_OF_MONTH,1);
dt=calendar.getTime();returndt;
}public staticString getDateString(Date date){
String sDate= "";
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Date dt=getDate(date);
sDate=sdf.format(dt);returnsDate;
}public static longgetDateLong(Date date){long lDate = 0;
Date dt=getDate(date);
lDate=dt.getTime();returnlDate;
}public static longgetDateTimeLong(Date date){long lDate = 0;
lDate=date.getTime();returnlDate;
}public staticString getString(Date date, String format){
String sDate="";
SimpleDateFormat sdf= newSimpleDateFormat(format);
sDate=sdf.format(date);returnsDate;
}public static longgetString(String dateTime, String format){long lDate = 0;
SimpleDateFormat sdf= newSimpleDateFormat(format);try{
Date date=sdf.parse(dateTime);
lDate=date.getTime();
}catch(ParseException e) {//TODO Auto-generated catch block
e.printStackTrace();
}returnlDate;
}public static String getString(longtm, String format){
String sDate="";
Date date=DateUtil.putDateTime(tm);
SimpleDateFormat sdf= newSimpleDateFormat(format);
sDate=sdf.format(date);returnsDate;
}public static Date putDateTime(longtime){
Date date= null;
date= newDate(time);returndate;
}public static Date putDate(longtime){
Date date= null;
date= newDate(time);
date=getDate(date);returndate;
}public staticDate putDateTime(String dtString, String format){
Date date= null;
SimpleDateFormat sdf= newSimpleDateFormat(format);try{
date=sdf.parse(dtString);
}catch(ParseException e) {//TODO Auto-generated catch block
e.printStackTrace();
}returndate;
}public static Date AddYear(Date date, inty){
Date dt= null;
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR, y);
dt=calendar.getTime();returndt;
}public static Date AddMonth(Date date, intm){
Date dt= null;
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, m);
dt=calendar.getTime();returndt;
}public static Date AddDay(Date date, intd){
Date dt= null;
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, d);
dt=calendar.getTime();returndt;
}public static Date AddHour(Date date, inth){
Date dt= null;
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, h);
dt=calendar.getTime();returndt;
}public static Date AddMinute(Date date, intm){
Date dt= null;
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, m);
dt=calendar.getTime();returndt;
}public static Date AddSecond(Date date, ints){
Date dt= null;
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.SECOND, s);
dt=calendar.getTime();returndt;
}public static Date Add(Date date, intmillisecond){
Date dt= null;
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MILLISECOND, millisecond);
dt=calendar.getTime();returndt;
}public static longSubtrat(Date date1, Date date2){long l = 0;
l= date1.getTime() -date2.getTime();returnl;
}
}