ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)
creates an instance of ZonedDateTime strictly validating the combination of local date-time, offset and zone ID.
ofStrict
has the following syntax.
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)
The following example shows how to use ofStrict
.
import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; //from w w w .j av a 2 s. c om public class Main { public static void main(String[] args) { ZonedDateTime z = ZonedDateTime.ofStrict(LocalDateTime.now(),ZoneOffset.UTC,ZoneId.systemDefault()); System.out.println(z); } }