50,527
社区成员
发帖
与我相关
我的任务
分享
import java.util.Date;
import org.apache.commons.lang.time.DurationFormatUtils;
public class Test {
public static void main(String[] args) throws Exception {
Date start = java.sql.Timestamp.valueOf("2009-12-05 11:30:00");
Date end = java.sql.Timestamp.valueOf("2009-12-21 11:05:30");
String result = DurationFormatUtils.formatPeriod(start.getTime(), end.getTime(), "dd'天");
System.out.println(result);
}
}
public static void main (String[] args) {
String s1 = "2003-09-14";
String s2 = "2003-05-24";
String t1 = s1.replace('-','/');
String t2 = s2.replace('-','/');
try{
Date dt1= new Date(t1);
Date dt2= new Date(t2);
System.out.println("dt1="+dt1.getTime());
System.out.println("dt2="+dt2.getTime());
long l = dt1.getTime() - dt2.getTime();
System.out.println("---------->;"+l/60/60/1000/24);
}catch(Exception e){
System.out.println("exception"+e.toString());
}
}