Creates an Instant from java.util.Date or it's subclasses. - Java java.time

Java examples for java.time:Instant

Description

Creates an Instant from java.util.Date or it's subclasses.

Demo Code


//package com.java2s;
import java.time.*;
import java.util.Date;

public class Main {
    /**// w  w  w.  j ava 2  s . c  o  m
     * Creates an {@link Instant} from {@code java.util.Date} or it's subclasses. Null-safe.
     */
    public static Instant asInstant(Date date) {
        if (date == null)
            return null;
        else
            return Instant.ofEpochMilli(date.getTime());
    }
}

Related Tutorials