I am using the JCalendar from here: http://www.toedter.com/en/jcalendar/
I have used the JDateChooser to set date in a form and import into SqLite in the format yyyy-MM-dd. WhenI try retrieving the date in the same format yyyy-MM-dd from the database with this code:
Date date = rs.getDate(10);
fieldClose.setDate(date); //displays 01-Jan-1970 - I want (2013-01-08), one that is similar in database.
I have looked at stackoverflow, and some similar posts exists, but fails to show recommendations in terms of format yyyy-MM-dd and consideration of jCalender and SQLite so i am having to post this. any ideas how to achieve a date similar to database, in the same format it was inserted and of same type.
I have just tried this:
String date =rs.getString(10);
((JTextField)fieldClose.getDateEditor().getUiComponent()).setText(date);
returns:
2013-05-22 // comes in red line, meaning jDatechooser doesnt recognise it
解决方案
Use SimpleDateFormat, try this example
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);