我只是試圖使用下面的代碼在特定的TimeZone中將XMLGregorianCalendar
(我從JAXWS獲得的)實例轉換爲GregorianCalendar
。XMLGregorianCalendar到GregorianCalendar
日期是在美國東部時間快到了,我想將其轉換成GMT爲進一步節省到DB
//soap response <ns4:TimeStamp>2016-06-18T04:43:54-04:00</ns4:TimeStamp>
//dtime is what i got from JAXB for the above date, so I wrote::
Date date = dTime.toGregorianCalendar(TimeZone.getTimeZone("UTC"), Locale.US, null).getTime();
System.out.println(date);
輸出:Sat Jun 18 14:13:54 IST 2016
由於上述預期沒有工作,所以我試圖日期格式和其給出預期的結果。
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
GregorianCalendar gc = dTime.toGregorianCalendar();
System.out.println(df.format(gc.getTime()));
輸出:2016-06-18 08:43:54 +0000
可能是什麼這裏toGregorianCalendar(...)問題沒有得到想要的結果?
另外我注意到從上面得到的GregorianCalendar實例從到GregorianCalendar has fieldSet = false。不知道這是否導致問題。
java.util.GregorianCalendar中[時間= 1468382241000,areFieldsSet =假,areAllFieldsSet =假,寬大=真,區= sun.util.calendar.ZoneInfo [ID = 「UTC」,偏移= 0, dstSavings = 0,useDaylight =假,過渡= 0,lastRule =空],Firstdayofweek可= 1,minimalDaysInFirstWeek = 1,ERA = 1,YEAR = 2016,MONTH = 6,WEEK_OF_YEAR = 29,WEEK_OF_MONTH = 3,DAY_OF_MONTH = 12,DAY_OF_YEAR = 194,DAY_OF_WEEK = 3,DAY_OF_WEEK_IN_MONTH = 2,AM_PM = 1,HOUR = 11,HOUR_OF_DAY = 23,MINUTE = 57,SECOND = 21,微差= 0,ZONE_OFFSET = -14400000,DST_OFFSET = 0]
任何幫助將不勝感激..!!
如果輸入是「04:43:54」,輸出如何成爲'05:27:21'?時區更改不會影響秒數。 – Andreas
對不起,我錯誤地添加了錯誤的輸出。現在更正。 – bbajaj