首页javalegacy_date_timeJava Data Type - 如何在不同的时区转换日期/日历

Java Data Type - 如何在不同的时区转换日期/日历

我们想知道如何在不同的时区转换日期/日历。
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {
  public static void main(String[] args) {
    Date d = new Date();
    System.out.println(d);

    DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
    System.out.println(df.format(d));
    df.setTimeZone(TimeZone.getTimeZone("Europe/London"));
    System.out.println(df.format(d));
  }
}