Java Date to Instant asInstant(Date date)

Here you can find the source of asInstant(Date date)

Description

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

License

Apache License

Declaration

public static Instant asInstant(Date date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.time.*;
import java.util.Date;

public class Main {
    /**/*from  w ww.j  av a  2  s .co  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

  1. toInstant(Date date)
  2. toInstant(Date date)
  3. toInstant(Date date)