看看这个是不是你要的结果: SimpleDateFormat format=new SimpleDateFormat("yyyy-mm-dd H:mm:ss"); Date date=format.parse("2008-9-27 13:05:00"); Date date1=format.parse("2008-9-27 14:05:00"); long begin=date.getTime(); long end=date1.getTime(); long time=(begin>end)?begin-end:end-begin; System.out.println(time);//打印的结果是毫秒;
Date d = new GregorianCalendar(2008, 9, 27, 13, 05).getTime(); Calendar now = Calendar.getInstance(); Calendar t1 = Calendar.getInstance(); t1.setTime(d);
判断此 Calendar 表示的时间是否在指定 Object 表示的时间之前,返回判断结果。
Calendar.after(Object when)
判断此 Calendar 表示的时间是否在指定 Object 表示的时间之后,返回判断结果。
SimpleDateFormat format=new SimpleDateFormat("yyyy-mm-dd H:mm:ss");
Date date=format.parse("2008-9-27 13:05:00");
Date date1=format.parse("2008-9-27 14:05:00");
long begin=date.getTime();
long end=date1.getTime();
long time=(begin>end)?begin-end:end-begin;
System.out.println(time);//打印的结果是毫秒;
Calendar.before(Object when)
判断此 Calendar 表示的时间是否在指定 Object 表示的时间之前,返回判断结果。
Calendar.after(Object when)
判断此 Calendar 表示的时间是否在指定 Object 表示的时间之后,返回判断结果。
Calendar now = Calendar.getInstance();
Calendar t1 = Calendar.getInstance();
t1.setTime(d);
System.out.println( now.compareTo(t1) );我想准确知道相差多少..
public static void main(String[] args) throws Exception {
String DATE_FORMAT = "yyyy-MM-dd hh:mm";
Date d = new Date();
SimpleDateFormat s = new SimpleDateFormat(DATE_FORMAT);
Date time1 = s.parse("2008-6-1 10:10");
Date time2 = s.parse("2008-8-1 10:10");
System.out.println((time2.getTime() - time1.getTime()) / (1000 * 3600 * 24)); }