Java LocalDate Calculate withTime(LocalDate day, int hours, int minutes)

Here you can find the source of withTime(LocalDate day, int hours, int minutes)

Description

with Time

License

Open Source License

Declaration

public static Instant withTime(LocalDate day, int hours, int minutes) 

Method Source Code


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

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

import java.util.Date;

public class Main {
    public static Instant withTime(LocalDate day, int hours, int minutes) {
        if (day == null) {
            day = LocalDate.now();
        }/*  w  w w.ja  va2  s  .c o m*/
        LocalDateTime dateTime = LocalDateTime.of(day, LocalTime.of(hours, minutes));
        return toInstant(dateTime);
    }

    public static Instant toInstant(Date date) {
        if (date == null) {
            return null;
        }
        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. stringToLocalDate(String birthDate)
  2. subscriptionDeletionRequired(LocalDate vehicleMotExpiryDate, LocalDate requestDate)
  3. toMilliseconds(LocalDate localDate)
  4. toPgDays(LocalDate date)
  5. withinAYearFromNow(LocalDate date)
  6. yyyyMMddToLocalDate(String dateStr)