javafx日期控件

package com.taocares.naoms.client.model.common.custom.control;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;

import javafx.beans.NamedArg;
import javafx.beans.property.LongProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.SpinnerValueFactory;
import javafx.util.StringConverter;

public class LocalDateTimeSpinnerValueFactory extends SpinnerValueFactory{
/**
* Creates a new instance of the LocalDateSpinnerValueFactory, using the
* value returned by calling {@code LocalDate#now()} as the initial value,
* and using a stepping amount of one day.
*/
public LocalDateTimeSpinnerValueFactory() {
this(LocalDateTime.now());

}

/**
 * Creates a new instance of the LocalDateSpinnerValueFactory, using the
 * provided initial value, and a stepping amount of one day.
 *
 * @param initialValue The value of the Spinner when first instantiated.
 */
public LocalDateTimeSpinnerValueFactory(@NamedArg("initialValue") LocalDateTime initialValue) {
    this(LocalDateTime.MIN, LocalDateTime.MAX, initialValue);
}

/**
 * Creates a new instance of the LocalDateSpinnerValueFactory, using the
 * provided initial value, and a stepping amount of one day.
 *
 * @param min The minimum allowed double value for the Spinner.
 * @param max The maximum allowed double value for the Spinner.
 * @param initialValue The value of the Spinner when first instantiated.
 */
public LocalDateTimeSpinnerValueFactory(@NamedArg("min") LocalDateTime min,
                                    @NamedArg("min") LocalDateTime max,
                                    @NamedArg("initialValue") LocalDateTime initialValue) {
    this(min, max, initialValue, 1, ChronoUnit.DAYS,"yyyy-MM-dd HH:mm:ss");
}

/**
 * Creates a new instance of the LocalDateSpinnerValueFactory, using the
 * provided min, max, and initial values, as well as the amount to step
 * by and {@link java.time.temporal.TemporalUnit}.
 *
 * <p>To better understand, here are a few examples:
 *
 * <ul>
 *     <li><strong>To step by one day from today: </strong> {@code new LocalDateSpinnerValueFactory(LocalDate.MIN, LocalDate.MAX, LocalDate.now(), 1, ChronoUnit.DAYS)}</li>
 *     <li><strong>To step by one month from today: </strong> {@code new LocalDateSpinnerValueFactory(LocalDate.MIN, LocalDate.MAX, LocalDate.now(), 1, ChronoUnit.MONTHS)}</li>
 *     <li><strong>To step by one year from today: </strong> {@code new LocalDateSpinnerValueFactory(LocalDate.MIN, LocalDate.MAX, LocalDate.now(), 1, ChronoUnit.YEARS)}</li>
 * </ul>
 *
 * @param min The minimum allowed double value for the Spinner.
 * @param max The maximum allowed double value for the Spinner.
 * @param initialValue The value of the Spinner when first instantiated.
 * @param amountToStepBy The amount to increment or decrement by, per step.
 * @param temporalUnit The size of each step (e.g. day, week, month, year, etc)
 */
public LocalDateTimeSpinnerValueFactory(@NamedArg("min") LocalDateTime min,
                                    @NamedArg("min") LocalDateTime max,
                                    @NamedArg("initialValue") LocalDateTime initialValue,
                                    @NamedArg("amountToStepBy") long amountToStepBy,
                                    @Na
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JavaFX提供了一个名为DatePicker的日期选择控件和一个名为TimePicker的时间选择控件。这两个控件都位于javafx.scene.control包中。 DatePicker控件允许用户选择日期。您可以使用它来选择特定的年、月和日。以下是一个简单的示例代码,演示如何在JavaFX中使用DatePicker控件: ```java import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.DatePicker; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) { DatePicker datePicker = new DatePicker(); VBox vbox = new VBox(datePicker); Scene scene = new Scene(vbox, 300, 200); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` TimePicker控件允许用户选择时间。您可以使用它来选择特定的小时和分钟。以下是一个简单的示例代码,演示如何在JavaFX中使用TimePicker控件: ```java import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TimePicker; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) { TimePicker timePicker = new TimePicker(); VBox vbox = new VBox(timePicker); Scene scene = new Scene(vbox, 300, 200); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` 这些示例代码创建了一个包含DatePicker或TimePicker控件的简单JavaFX应用程序窗口。您可以根据需要自定义这些控件的外观和行为。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值