Java LocalDateTime to getDate(LocalDateTime time)

Here you can find the source of getDate(LocalDateTime time)

Description

Creates a java.util.Date from the given java.time.LocalDateTime based on the UTC time zone.

License

Open Source License

Parameter

Parameter Description
time the LocalDateTime.

Return

a Date.

Declaration

public static Date getDate(LocalDateTime time) 

Method Source Code

//package com.java2s;

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

import java.util.Date;

public class Main {
    /**/*w  ww .  java  2s  .com*/
     * Creates a {@link java.util.Date} from the given {@link java.time.LocalDateTime}
     * based on the UTC time zone.
     *
     * @param time the LocalDateTime.
     * @return a Date.
     */
    public static Date getDate(LocalDateTime time) {
        Instant instant = time.toInstant(ZoneOffset.UTC);

        return Date.from(instant);
    }
}

Related

  1. convertLocalDateTimeToDateInUTC(final LocalDateTime ldt)
  2. convertToDate(LocalDateTime dateTime)
  3. fromLocalDateTime(LocalDateTime _ldt)
  4. getDateTimeText(LocalDateTime dateTime)
  5. getDelayUntil(final LocalDateTime ldt)
  6. getDifference(LocalDateTime sourceTime, LocalDateTime targetTime)
  7. getDurationInMillis(LocalDateTime from, LocalDateTime to)