随笔-10  评论-23  文章-32  trackbacks-0
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
class Test2 {
public static String getDate(){
SimpleDateFormat ft
= new SimpleDateFormat("yyyy/MM/dd");
Date dd
= new Date();
return
ft.format(dd);
}
public static long getQuot(String time1, String time2){
long quot = 0;
SimpleDateFormat ft
= new SimpleDateFormat("yyyy/MM/dd");
try {
Date date1
= ft.parse( time1 );
Date date2
= ft.parse( time2 );
quot
= date1.getTime() - date2.getTime();
quot
= quot / 1000 / 60 / 60 / 24;
}
catch (ParseException e) {
e.printStackTrace();
}

return
quot;
}
public static void main(String[] args) throws Exception {
String date1
= "2008/8/8";
String date2
= getDate();
long day = getQuot(date1,date2);
System.out.println(
"距离 "+date1+" 还有 "+day+"" );
}
}
posted on 2009-08-04 16:01 liuyimx 阅读(300) 评论(0)  编辑  收藏 所属分类: java基础

只有注册用户登录后才能发表评论。


网站导航: