首页 > 解决方案 > How to display day from selected date using javafx?

问题描述

I want to know the code how to get the day name of a selected date which select from the datepicker to a textfield using javafx and scenebuilder.

I use “Windows 10, MySQL 5.7.

this is what i tried. I want to get the day name of date in "txtDate" and set it to txtDay instead of adding it manually.

name of the datepicker field is txtDate) name of the text field is txtDay)

enter image description here

标签: javafx

解决方案


你应该只使用DateTimeFormatter

例子

LocalDate day = LocalDate.now(); // or myDatePicker.getValue()
DateTimeFormatter format = DateTimeFormatter.ofPattern("EEEE", Locale.getDefault());
System.out.println(day.format(format));
myLabel.setText(day.format(format));

你会看到你想要什么“星期三”


推荐阅读