Java Date to Instant toInstant(Date date)

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

Description

to Instant

License

Open Source License

Declaration

public static Instant toInstant(Date date) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.Instant;

import java.time.LocalDateTime;

import java.time.ZoneId;

import java.util.Date;

public class Main {
    public static Instant toInstant(Date date) {
        if (date == null) {
            return null;
        }/* www .ja  v a  2 s. co m*/
        Instant moment = Instant.ofEpochMilli(date.getTime());
        return moment;
    }

    public static Instant toInstant(LocalDateTime localDateTime) {
        if (localDateTime == null) {
            return null;
        }
        Instant moment = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        return moment;
    }
}

Related

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