SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
ParsePosition pos1 = new ParsePosition(0);
Date dt1 = formatter.parse(d1, pos);
Date dt2 = formatter.parse(d2, pos1);
long l = dt1.getTime() - dt2.getTime();
i = l / (1000 * 60 * 60 * 24);
// 这是他们相差的天数。
System.out.println("Hello World!=" + i);
} catch (Exception
复制代码
作者: 2012 时间: 2013-9-16 19:01
解题思路:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date now = df.parse("2013-12-3 13:31:40");
java.util.Date date=df.parse("2013-11-12 13:21:00");
long l=now.getTime()-date.getTime();
long day=l/(24*60*60*1000);
long hour=(l/(60*60*1000)-day*24);
long min=((l/(60*1000))-day*24*60-hour*60);
long s=(l/1000-day*24*60*60-hour*60*60-min*60);
System.out.println(""+day+"天"+hour+"小时"+min+"分"+s+"秒");