How do i convert the date what I fetch from the database to 06.10.2010
yyyy-MM-dd to dd.MM.yyyy
Printable View
How do i convert the date what I fetch from the database to 06.10.2010
yyyy-MM-dd to dd.MM.yyyy
SimpleDateFormat
The date you fetch from a database has no format, so you are not changing from one String format to another. Unless, of course, it's not actually a DATE column...
Just thought I'd throw that in there...:)
Thanks, got it, simpledateformat did the trick.
Here's the code:
Code://create SimpleDateFormat object with source string date format
SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdfSource.parse(rs.getString(3));
//New date format
DateFormat dateformat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
//Convert
String newDate = dateformat.format(date);
No no no.
Why are you converting the perfectly useable Date object back to a String?
I do hope you are not inserting that String into the db and letting the db auto-convert to a DATE...that's a Bad Thing.
which database are u using...(SINGH IS KING):p