我的代码似乎有问题。我希望我的输出中有不同的时间——一个从 UTC 转换为德国时间,一个转换为巴西东部时间,但我总是得到相同的 UTC 时间输出。
我的代码:
LocalDateTime localDateTime = resource.getDateOfManufacture();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy_HH-mm-ss", Locale.getDefault());
ZoneId zoneDE = ZoneId.of("Europe/Berlin");
ZoneId zoneBR = ZoneId.of("Brazil/East");
System.out.println("TIME --------------------------------------------------------------------");
System.out.println(localDateTime);
System.out.println(localDateTime.atZone(zoneDE));
System.out.println(localDateTime.atZone(zoneBR));
System.out.println(localDateTime.atZone(zoneDE).format(dateTimeFormatter));
System.out.println(localDateTime.atZone(zoneBR).format(dateTimeFormatter));
我的实际输出:
13:06:43,890 INFO [stdout] (EJB default - 2) TIME --------------------------------------------------------------------
13:06:43,904 INFO [stdout] (EJB default - 2) 2016-05-31T22:00
13:06:43,907 INFO [stdout] (EJB default - 2) 2016-05-31T22:00+02:00[Europe/Berlin]
13:06:43,908 INFO [stdout] (EJB default - 2) 2016-05-31T22:00-03:00[Brazil/East]
13:06:43,913 INFO [stdout] (EJB default - 2) 31-05-2016_22-00-00
13:06:43,917 INFO [stdout] (EJB default - 2) 31-05-2016_22-00-00
我的期望(关于最后两行):
13:06:43,890 INFO [stdout] (EJB default - 2) TIME --------------------------------------------------------------------
13:06:43,904 INFO [stdout] (EJB default - 2) 2016-05-31T22:00
13:06:43,907 INFO [stdout] (EJB default - 2) 2016-05-31T22:00+02:00[Europe/Berlin]
13:06:43,908 INFO [stdout] (EJB default - 2) 2016-05-31T22:00-03:00[Brazil/East]
13:06:43,913 INFO [stdout] (EJB default - 2) 01-06-2016_00-00-00
13:06:43,917 INFO [stdout] (EJB default - 2) 31-05-2016_19-00-00