1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package com.smobob.datetime;
import java.time.Period; import java.time.ZoneId; import java.time.ZonedDateTime;
public class ZonedDateTimeExample {
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); System.out.println("dateTime: " + dateTime); System.out.println("zoneDateTime : " + dateTime);
ZoneId zoneId = ZoneId.of("UTC+8"); ZonedDateTime dateTime2 = ZonedDateTime.of(2018, 3, 8, 23, 45, 59, 1234, zoneId);
ZonedDateTime zoneDateTime = dateTime2.plus(Period.ofDays(3)); System.out.println("zoneDateTime : " + zoneDateTime);
ZoneId zoneId2 = ZoneId.of("Europe/Copenhagen"); ZoneId zoneId3 = ZoneId.of("Europe/Paris");
System.out.println("zoneId2: " + zoneId2); System.out.println("zoneId3: " + zoneId3); }
}
|