需要做一个时间差的判断,有点不想写,于是翻以前的代码发现,米有....现在来记录一下吧
public static void main(String[] args) throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date currentTime=new Date();
//将截取到的时间字符串转化为时间格式的字符串
Date beginTime=sdf.parse("2011-09-14 12:53:30");
//默认为毫秒,除以1000是为了转换成秒
long interval=(currentTime.getTime()-beginTime.getTime())/1000;//秒
long day=interval/(24*3600);//天
long hour=interval%(24*3600)/3600;//小时
long minute=interval%3600/60;//分钟
long second=interval%60;//秒
System.out.println("两个时间相差:"+day+"天"+hour+"小时"+minute+"分"+second+"秒");
}
public static void main(String[] args) throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date currentTime=new Date();
//将截取到的时间字符串转化为时间格式的字符串
Date beginTime=sdf.parse("2011-09-14 12:53:30");
//默认为毫秒,除以1000是为了转换成秒
long interval=(currentTime.getTime()-beginTime.getTime())/1000;//秒
long day=interval/(24*3600);//天
long hour=interval%(24*3600)/3600;//小时
long minute=interval%3600/60;//分钟
long second=interval%60;//秒
System.out.println("两个时间相差:"+day+"天"+hour+"小时"+minute+"分"+second+"秒");
}