我在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