我在IST時間在Java中有一個Date字段。我想將其轉換爲EST時間,並且輸出應僅作爲日期類型。我可以使用下面的代碼來完成相同的: -IST到EST在Java中的時間轉換
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
dateTimeFormat.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
Date date = new Date();
DateFormat timeFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
timeFormat.setTimeZone(TimeZone.getTimeZone("America/New_York"));
String estTime = timeFormat.format(date);
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.ENGLISH).parse(estTime);
與上面這段代碼的問題是,雖然日期是美國東部時間時間轉換,時區仍然顯示爲IST和而不是EST。日期的其餘部分轉換得很好。有沒有什麼辦法可以明確地設置日期字段中的時區到EST。任何有關這方面的幫助將不勝感激。
-Subhadeep
'dateTimeFormat'是在代碼中未使用的變量。 – 2013-03-18 12:42:53