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("2010-07-27 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+"秒");