这是我的代码片段。我当地的时区是“亚洲/孟买”。时区变为GMT,尽管我正在覆盖时区
SimpleDateFormat isoFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
Date date1 = isoFormat.parse("03/01/2016 09:01 AM");
isoFormat.setTimeZone(TimeZone.getTimeZone("Asia/Mumbai"));
isoFormat.applyPattern("dd MMM yyyy HH:mm:ss z");
System.out.println("Current Date and Time in IST time zone: " + isoFormat.format(date1));
但在输出我得到:
目前在IST时区的日期和时间:2016年3月1日3时31分00秒GMT
谁能告诉为什么重写一个时区是我的本地时区也可以将其更改为GMT吗?
尽管JST或SGT的代码工作正常,
isoFormat.setTimeZone(TimeZone.getTimeZone("Asia/Singapore"));
isoFormat.applyPattern("dd MMM yyyy HH:mm:ss z");
System.out.println("Current Date and Time in SGT time zone: " + isoFormat.format(date1));
isoFormat.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
isoFormat.applyPattern("dd MMM yyyy HH:mm:ss z");
System.out.println("Current Date and Time in JST time zone: " + isoFormat.format(date1));
输出:
当前日期和时间在SGT时区:2016年3月1日11时31分00秒SGT
当前日期和时间JST时区:2016年3月1日12:31 :00 JST
是的,我应该检查清单。我认为如果我们使用https://en.wikipedia.org/wiki/List_of_tz_database_time_zones会更好 – Learner