0

I Get the following Date from my SQLite database which get pulled down as a string in the following format '03-07-2015'.

I want this format to display like this 'Fri 3rd July 2015' I am doing this using SimpleDateFormat, I then need to pass this into an ArrayList, I cannot quite get this to work, any advice to what I am doing wrong would be much appreciated.

String dayNumberSuffix = getDayOfMonthSuffix(3);
SimpleDateFormat sdf = new SimpleDateFormat("EEEE dd'" + dayNumberSuffix + "' MMMM yyyy");
String d = sdf.format(cursor.getString(1));
dates.add(d); // ArrayList<String>

String getDayOfMonthSuffix(final int n) {
    switch (n % 10) {
        case 1:  return "st";
        case 2:  return "nd";
        case 3:  return "rd";
        default: return "th";
    }
}

I have tried a few different variations, but I believe the one above is closest.

1
  • Whats the result of the method you have tried? Commented Jul 3, 2015 at 14:27

1 Answer 1

2

you need to parse the date in the parse 03-07-2015, that you get from your database and format it:

String dayNumberSuffix = getDayOfMonthSuffix(3);
SimpleDateFormat parseSDF = new SimpleDateFormat("dd-MM-yyyy");

SimpleDateFormat sdf = new SimpleDateFormat("EEEE dd'" + dayNumberSuffix + "' MMMM yyyy");
Date date = parseSDF.parse(cursor.getString(1));
String d = sdf.format(date);
dates.add(d); // ArrayList<String>

should do it

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.