Returns a LocalDateTime instance for the specified date with time set to 12:00:00. - Java java.time

Java examples for java.time:LocalDateTime

Description

Returns a LocalDateTime instance for the specified date with time set to 12:00:00.

Demo Code


//package com.java2s;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Main {
    /**/*from  w  w w.j a v  a2 s  .  c om*/
     * Returns a LocalDateTime instance for the specified date with time set to 12:00:00.
     * When no date is specified then the current date will be used.
     *
     * @param date contains the date to be used (optional)
     * @return the created LocalDateTime
     */
    public static LocalDateTime getNoonDateTimeForDate(final LocalDate date) {
        final LocalDate tempDate = date == null ? LocalDate.now() : date;
        return LocalDateTime.of(tempDate, LocalTime.of(12, 0));
    }
}

Related Tutorials