Close

Java Date Time - ZoneId.from() Examples

Java Date Time Java Java API 


Class:

java.time.ZoneId

java.lang.Objectjava.lang.Objectjava.time.ZoneIdjava.time.ZoneIdjava.io.SerializableSerializableLogicBig

Method:

public static ZoneId from(TemporalAccessor temporal)

Obtains an instance of ZoneId from the specified temporal object.


Examples


package com.logicbig.example.zoneid;

import java.time.*;
import java.time.temporal.TemporalAccessor;

public class FromExample {

public static void main(String... args) {
from(OffsetTime.now());
from(OffsetDateTime.now());
from(ZonedDateTime.now());
from(ZoneOffset.ofHoursMinutes(-5, 0));
}

private static void from(TemporalAccessor t) {
ZoneId z = ZoneId.from(t);
System.out.printf("%15s > %s > %s%n", t.getClass().getSimpleName(), t, z);
}
}

Output

     OffsetTime > 15:51:08.436-05:00 > -05:00
OffsetDateTime > 2017-05-01T15:51:08.486-05:00 > -05:00
ZonedDateTime > 2017-05-01T15:51:08.487-05:00[America/Chicago] > America/Chicago
ZoneOffset > -05:00 > -05:00




See Also