Close

Java Date Time - Instant.from() Examples

Java Date Time Java Java API 


Class:

java.time.Instant

java.lang.Objectjava.lang.Objectjava.time.Instantjava.time.Instantjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public static Instant from(TemporalAccessor temporal)

This method creates a new instance of the Instant object based on the specified temporal.


Examples


package com.logicbig.example.instant;

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAccessor;

public class FromExample {

public static void main(String... args) {
from(OffsetDateTime.now());
from(ZonedDateTime.now());
from(Instant.now());
}

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

Output

from OffsetDateTime > 2017-05-01T15:57:59.774-05:00 > 2017-05-01T20:57:59.774Z
from ZonedDateTime > 2017-05-01T15:57:59.814-05:00[America/Chicago] > 2017-05-01T20:57:59.814Z
from Instant > 2017-05-01T20:57:59.814Z > 2017-05-01T20:57:59.814Z




See Also