java中的日期时间的计算与比较
生活随笔
收集整理的這篇文章主要介紹了
java中的日期时间的计算与比较
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在JAVA中日期的計算與比較可以使用Date和DateFormat來解決
public?class?Test{
public?static?void?main(String[]?args){
try{
Date?date=new?Date();
DateFormat?df=DateFormat.getDateTimeInstance();
String?now=df.format(date);?
System.out.println("現(xiàn)在時間:"+now);
System.out.println("現(xiàn)在時間是否在16:00之前:"+date.before(df.parse("2008-07-09?16:00:00")));?
}
catch(ParseException?e){System.out.print(e.getMessage());
}
}
}
public?class?Test{
public?static?void?main(String[]?args){
try{
Date?date=new?Date();
DateFormat?df=DateFormat.getDateTimeInstance();
String?now=df.format(date);?
System.out.println("現(xiàn)在時間:"+now);
System.out.println("現(xiàn)在時間是否在16:00之前:"+date.before(df.parse("2008-07-09?16:00:00")));?
}
catch(ParseException?e){System.out.print(e.getMessage());
}
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/wllyy189/archive/2008/07/09/1238700.html
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的java中的日期时间的计算与比较的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个 .Net Hashtable 的锁
- 下一篇: 如何在三个月掌握三年的经验