集册 Java实例教程 将时区中的日期时间转换为另一时区

将时区中的日期时间转换为另一时区

欢马劈雪     最近更新时间:2020-01-02 10:19:05

399
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将时区中的日期时间转换为另一时区

import java.time.LocalDateTime;

import java.time.Month;

import java.time.ZoneId;

import java.time.ZonedDateTime;/*来 自 n o w j a v a . c o m*/


public class Main {

  public static void main(String[] args) {

    LocalDateTime ldt = LocalDateTime.of(2019, Month.MAY, 14, 16, 30);


    ZoneId usCentral = ZoneId.of("America/Chicago");

    ZonedDateTime zdt = ZonedDateTime.of(ldt, usCentral);

    System.out.println("In US Central Time Zone:" + zdt);


    ZoneId asiaKolkata = ZoneId.of("Asia/Kolkata");

    ZonedDateTime zdt2 = zdt.withZoneSameInstant(asiaKolkata);

    System.out.println("In Asia/Kolkata Time Zone:" + zdt2);


    ZonedDateTime zdt3
展开阅读全文