Reputation: 2737
I have a Date column in sqlite database. With the help of cursor I am able to retrieve the values from that column. The Values are in this format, "YYYY-mm-dd". I want them to be converted to this format, "Mar 08 2013". How is this possible with SimpleDateFormat?
Can any one suggest please!! Any help will be Appreciated!!
Thanks.
Upvotes: 0
Views: 397
Reputation: 33495
Here is one quick solution:
String sourceDate = c.getString(<columnNumber>);
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd yyyy");
Date formatted = null;
try {
formatted = formatter.parse(sourceDate);
}
catch (ParseException ex) {
Log.w("ParseError", ex.getMessage());
}
String formattedString = formatter.format(formatted);
Upvotes: 0
Reputation: 363469
I suggest you to use DateUtils. It contains a lot of static methods to help you format date, times, time deltas into a human-readable String.
http://developer.android.com/reference/android/text/format/DateUtils.html
Upvotes: 1