java中DateTime类的使用

来源:互联网 发布:java 当前时间 年月日 编辑:程序博客网 时间:2024/06/05 17:04

1、 获取当前系统时间:DateTime.now(); 返回的是一个DateTime对象。

2、DateTime转换成Date

(1)DateTime.now().toDate(); 

(2)newDateTime("2014-10-29").toDate(); 

(3)new DateTime("2014-10-2915:19:23").toDate(); 

3、转换成字符串格式

(1)new DateTime(newDate()).toDateString(),返回的是 2014-10-29 这种格式的字符串

(2)new DateTime(newDate()).toDateTimeString(),返回的是2014-10-29 15:23:23 这种格式的字符串

(3new DateTime(new Date()).toDateTimeString("yyyy年MM月dd日"); 

(4)new DateTime(newDate()).toDateTimeString("yyyy年MM月dd日 hh时mm分ss秒"); 

 


0 0