Mahe
Mahe

Reputation: 2737

Android SimpleDateFormat

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

Answers (2)

Simon Dorociak
Simon Dorociak

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

Gabriele Mariotti
Gabriele Mariotti

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

Related Questions