Java LocalDateTime to Instant toInstant(final LocalDateTime dateTime)

Here you can find the source of toInstant(final LocalDateTime dateTime)

Description

Convert a given LocalDateTime to an Instant .

License

Apache License

Parameter

Parameter Description
dateTime The date/time to convert to an Instant .

Return

The corresponding to the provided date/time.

Declaration

public static Instant toInstant(final LocalDateTime dateTime) 

Method Source Code

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

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

public class Main {
    /**/*from   w  w w . j av a 2 s  . c o  m*/
     * Convert a given {@link LocalDateTime} to an {@link Instant}. In order to convert it, the method
     * {@link LocalDateTime#toInstant(ZoneOffset)} is called with the offset determined using
     * {@link ZoneOffset#of(String)} with {@link ZoneOffset#UTC} as argument.
     * @param dateTime The date/time to convert to an {@link Instant}.
     * @return The {@link Instant} corresponding to the provided date/time.
     */
    public static Instant toInstant(final LocalDateTime dateTime) {
        return dateTime.toInstant(ZoneOffset.of(ZoneOffset.UTC.toString()));
    }
}