2014-01-15 38 views
-2

請在格式轉換數據幫助 」2007年5月16日12:00:00 AM「 以GMT數據格式2007-05-16T12:00:00.000 + 0000 「在Java中使用 以下方法像 「轉換日期爲GMT日期格式

public String getGMTMillis(Date time) 
{ 
    if (time != null) 
    { 
     Calendar calendar = Calendar.getInstance(); 
     calendar.setTime(time); 
     calendar.setTimeZone(TimeZone.getTimeZone("GMT")); 

     return "" + calendar.getTimeInMillis(); 
    } 

    return ""; 
} 
+1

把你的標題,並在谷歌搜索中使用它。 –

回答

1

嘗試:

public String getGmtMillis(Date time) 
{ 
    if (time == null) 
    { 
     return ""; 
    } 
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"); 
    df.setTimeZone(TimeZone.getTimeZone("GMT")); 
    return df.format(time); 
} 
0

我相信你所要求的ISO 8601標準日期時間格式。

Joda-Time 2.3庫使用該標準格式作爲其默認的toString方法。

String dateTimeString = new DateTime(DateTimeZone.UTC); 

輸出將是這樣的:

2014-01-18T12:34.123Z