Java Clock date(LocalDate date)

PreviousNext

Return:

passed in local date converted to date using the default clock

The method source code is listed as follows:

/**
 * @return passed in local date converted to date using the default clock
 */
public static Date date(LocalDate date) {
    return date(date, DEFAULT_CLOCK);
}

The complete source code is listed as follows:

//package com.java2s;
import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalDateTime;

import java.util.Date;

public class Main {
    private static final Clock DEFAULT_CLOCK = Clock.systemUTC();

    /**//    w w   w  .d   e  m   o 2  s  .  c   o m 
     * @return passed in local date converted to date using the default clock
     */
    public static Date date(LocalDate date) {
        return date(date, DEFAULT_CLOCK);
    }

    /**
     * @return passed in local date time converted to date using the provided clock
     */
    public static Date date(LocalDateTime date, Clock clock) {
        return Date.from(date.atZone(clock.getZone()).toInstant());
    }

    /**
     * @return passed in local date time converted to date using the default clock
     */
    public static Date date(LocalDateTime date) {
        return date(date, DEFAULT_CLOCK);
    }

    /**
     * @return passed in local date converted to date using the provided clock
     */
    public static Date date(LocalDate date, Clock clock) {
        return Date.from(date.atStartOfDay().atZone(clock.getZone()).toInstant());
    }
}
PreviousNext

Related