java 如何将 DatePicker 值转换为字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33789307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert DatePicker Value to String?
提问by user3153278
I'm trying to convert the
我正在尝试转换
datepicker.getvalue();
datepicker.getvalue();
into a String(or into something else, which I can then use to insert into my mysql database), but I've been having troubles finding information about that!
到一个字符串(或其他东西,然后我可以用它插入到我的 mysql 数据库中),但是我一直在寻找有关它的信息时遇到麻烦!
Have you got any suggestions?Thanks! :)
你有什么建议吗?谢谢!:)
EDIT:This solves the problem
编辑:这解决了问题
String date = datepicker.getValue().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
回答by Madushan Perera
You can get the string value of selected date with desire format like below :
您可以使用以下格式获取所选日期的字符串值:
String date = datepicker.getValue().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
or
you can get java.sql.Date straight away to your database table :
或者
您可以立即将 java.sql.Date 获取到您的数据库表中:
java.sql.Date sqlDate =java.sql.Date.valueOf(datepicker.getValue());