【发布时间】:2016-03-01 11:44:19
【问题描述】:
这是我的代码 sn-p。我的本地时区是“亚洲/孟买”。
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 日 03:31:00 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
【问题讨论】: