2011-05-24 129 views
0

我有以下日期:如何將UTC轉換爲DateTime?

2011-05-24T11:40:41Z 

我如何轉換這成喬達日期時間?

編輯: 這裏是我的代碼無法編譯:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 
         Date date = df.parse(aMessage.getString("updated_at")); 
         org.joda.time.DateTime dt = new DateTime(date); 

錯誤:

The method parse(String) is undefined for the type DateFormat 
Type mismatch: cannot convert from SimpleDateFormat to DateFormat 

回答

1

從Joda的user guide

所有的印刷和解析使用DateTimeFormatter對象執行。

你應該能夠只需直接在這種情況下使用ISODateTimeFormat工廠:

String inputDateString = "2011-05-24T11:40:41Z"; 

DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis(); 
DateTime result = fmt.parseDateTime(inputDateString); 
0

使用DatFormat。它有一個parse()方法可以使用。

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 
    df.parse("2011-05-24T11:40:41Z"); 
    org.joda.time.DateTime dt = new DateTime(date); 
+0

你能否告訴我這一次的例子嗎? – 2011-05-24 15:44:04

+0

是的,喬達日期時間 – 2011-05-24 15:48:12

+0

我已經更新了答案,告訴你如何:) – 2011-05-24 15:52:50