我正在使用这里的JCalendar
:http://www.toedter.com/en/jcalendar/
我使用 JDateChooser 在表单中设置日期并以 yyyy-MM-dd
格式导入到 SqLite
中。当我尝试使用以下代码从数据库中检索相同格式的日期 yyyy-MM-dd
时:
Date date = rs.getDate(10);
fieldClose.setDate(date); //displays 01-Jan-1970 - I want (2013-01-08), one that is similar in database.
我查看了 stackoverflow,并且存在一些类似的帖子,但未能显示格式 yyyy-MM-dd
方面的建议以及对 jCalender
和 SQLite 的考虑,因此我不得不发布这个。任何想法如何实现类似于数据库的日期,其插入格式相同且类型相同。
我刚刚尝试过这个:
String date =rs.getString(10);
((JTextField)fieldClose.getDateEditor().getUiComponent()).setText(date);
返回:
2013-05-22//红线表示 jDatechooser 无法识别
最佳答案
使用 SimpleDateFormat,试试这个例子
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date=null;
try{
date=sdf.parse(rs.getString(10));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fieldClose.setDate(date);
关于java - JCalendar - 使用正确的格式在 Java 中正确设置日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14238570/