public class DateUtils {
public static int diffDay(String d1,String d2,String patten){
SimpleDateFormat format=new SimpleDateFormat(patten);
Date date1=null;
Date date2=null;
int day=0;
try{
date1=format.parse(d1);
date2=format.parse(d2);
long m=Math.abs(date1.getTime()-date2.getTime());
day=(int)(m/1000/60/60/24);
}catch(ParseException e){
e.printStackTrace();
}
return day;
}
public static Date getdate(long m){
return new Date(m);
}
public static Date getcurrentdate(){
return new Date();
}
public static Date getchangedate(boolean isplus,int day){
//获得当前时间的时间戳(自1970年到)
long currenttime=System.currentTimeMillis();
long changetime=0;
if(isplus){
changetime=currenttime+(day*24*60*60*1000);
}else{
changetime=currenttime-(day*24*60*60*1000);
}
return new Date(changetime) ;
}
public static Date getchangetime(boolean isplus,int day,Date date){
long time=date.getTime();
long changeTime=0;
if(isplus) {
//添加日期
changeTime=time+(day*24*60*60*1000);
} else {
//减少日期
changeTime=time-(day*24*60*60*1000);
}
return new Date(changeTime);
}
public static String getformatdate(Date date,String format){
SimpleDateFormat simpleDateFormat=new SimpleDateFormat(format);
return simpleDateFormat.format(date);
}
public static long getCurrentMillis(){
return System.currentTimeMillis();
}
}
时间操作工具类
最新推荐文章于 2022-04-19 09:17:10 发布