2016-05-19 155 views
-1

我想将UTC时区(例如:2016-05-19T06:10:00)转换为CEST时区(2016-05-19T08:10:00)在Java中的字符串。如何将UTC从UTC时间转换为CEST时区

+0

另见http://stackoverflow.com/questions/12487125/java-how-do-you-convert-a-utc -timestamp-to-local-time – Unknown

+0

关于堆栈溢出,有很多类似的问题。请在询问之前搜索。谢谢。 – Sanjeev

+0

我已经通过他们,但没有用。 –

回答

1

java.time溶液:

public static void main(String[] args) { 
    String orgDate = "2016-05-19T06:10:00"; 
    String dstDate = LocalDateTime.parse(orgDate, DateTimeFormatter.ISO_LOCAL_DATE_TIME) 
            .atZone(ZoneId.of("UTC")) 
            .withZoneSameInstant(ZoneId.of("CET")) 
            .toLocalDateTime() 
            .toString(); // use a custom formatter 

    System.out.println(orgDate); 
    System.out.println(dstDate); 
} 

结果:

2016-05-19T06:10:00 
2016-05-19T08:10 
+0

对不起,我不明白,因为LocalDateTime不存在于java.Util包中,所以它显示错误。 –

+0

@KoneruKiranKumarReddy java. java.time包是在Java 8中添加的。 – Pshemo