我有一個由字符串「0002-01-04T00:49:40.000」表示的日期,即年份爲2CE的日期。我需要將它與時區標識「Etc/UTC」結合,將其轉換爲java.util.Date
的實例。以下代碼顯示我如何操作:當轉換爲java.util.Date時,將一年的2CE的LocalDateTime轉換爲一天
public static Date toDate(LocalDateTime localDateTime, String timezoneId){
if(localDateTime == null) return null;
if(timezoneId != null) {
localDateTime.toDateTime(DateTimeZone.forID(timezoneId)).toDate();
} else {
return localDateTime.toDateTime().toDate()
}
}
但是LocalDateTime.toDate()
無法正常工作。它迄今爲止增加了+1天。
「0002-01-04T00:49:40.000Z」--->「Thu Jan 05 16:49:40 PST 2」。
可能重複[如何使用GWT將日期時間字符串轉換爲日期?](http://stackoverflow.com/questions/11342670/how-to-convert-string-of-datetime-to-date -using-gwt) – DimaSan
'toDate()'是[JodaTime](http://www.joda.org/joda-time/)的方法。 – DimaSan
'java.util.Date.toString()'在0002年使用Julian日曆!所以我沒有看到問題或失敗。 –