Java代码  
1.System.out.println(new java.util.Date());  
输出:Thu Jan 27 14:43:28 CST 2011

2.System.out.println(new java.util.Date().toLocaleString());  
输出:2011-1-27 14:45:21

不过现在toLocaleString()方法已过时,由DateFormat.format(Date date)取代。

 

DateFormat ddf = DateFormat.getDateInstance();  
DateFormat dtf = DateFormat.getTimeInstance();  
DateFormat ddtf = DateFormat.getDateTimeInstance();  
Date date = new Date();  
System.out.println("日期:" + ddf.format(date));  
System.out.println("时间:" + dtf.format(date));  
System.out.println("日期时间:" + ddtf.format(date));  
SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getDateTimeInstance();  
System.out.println("日期时间:" + sdf.format(date)); 

 输出:

 日期:2011-2-9

时间:11:16:02

日期时间:2011-2-9 11:16:02

日期时间:2011-2-9 11:16:02

  

相关文章:

  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-09-11
  • 2021-06-01
猜你喜欢
  • 2021-06-30
  • 2021-06-18
  • 2021-08-09
  • 2021-05-29
  • 2021-10-10
  • 2022-12-23
  • 2021-08-14
相关资源
相似解决方案