get Date From JavaFX Date Picket - Java JavaFX

Java examples for JavaFX:Date Picker

Description

get Date From JavaFX Date Picket

Demo Code


//package com.java2s;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import javafx.scene.control.DatePicker;

public class Main {
    public static Date getDateFromDatePicket(DatePicker datePicker) {
        LocalDate localDate = datePicker.getValue();
        if (localDate != null) {
            Instant instant = Instant.from(localDate.atStartOfDay(ZoneId
                    .systemDefault()));//from   w ww  .  j  ava 2s. c o  m
            Date date = Date.from(instant);
            return date;
        } else {
            return null;
        }
    }
}

Related Tutorials