如何将JDateChooser字段的输出解析为有用的东西?

时间:2012-11-02 12:41:25

标签: simpledateformat parseexception jdatechooser

当我从JDateChooser获取日期时,我会得到类似的内容:

2012年11月2日星期五23:20:32 2012年

我尝试过使用SimpleDateFormat但是我收到一条错误,说它不可解析。

我需要格式化日期:“yyyy-MM-dd”

这是我正在使用的JDateChooser的API:http://www.toedter.com/en/jcalendar/api/com/toedter/calendar/JDateChooser.html

1 个答案:

答案 0 :(得分:1)

我似乎错误地使用了SimpleDateFormat。

解决方案是:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String startDateString = dateFormat.format(projectStartDateJDateChooser.getDate());