Mabjik
Mabjik

Reputation: 255

How to show day of the week + format Date

Calendar.getInstance();

mDateButton = (Button)v.findViewById(R.id.crime_date);
mDateButton.setText(DaySet(Calendar.DAY_OF_WEEK)+" "+DateFormat.getLongDateFormat(getActivity()).format(mCrime.getDate()));
mDateButton.setEnabled(false);



public String DaySet(int day){
        String mBuf="";
        switch (day){
        case 1: mBuf = "Sunday";
        break;

        case 2: mBuf = "Monday";
        break;

        case 3: mBuf = "Tuesday";
        break;

        case 4: mBuf = "Wensday";
        break;

        case 5: mBuf = "Thursday";
        break;

        case 6: mBuf = "Friday";
        break;

        case 7: mBuf = "Saturday";
        break;
        }

        return mBuf;
}

I need to show a date on the button that will look like "Tuesday, Feb 20 2014". So the second part of this date works, but first -doesn't. Calendar.DAY_OF_WEEK shows me wrong constant. Probably you know better methods?

Upvotes: 0

Views: 223

Answers (1)

Strigger
Strigger

Reputation: 1903

This code will format calendar object to "Thursday, Feb 20 2014"

SimpleDateFormat format = new SimpleDateFormat("cccc, MMM dd yyyy");
String formatDate = format.format(cal.getTime());

See SimpleDateFormat at the official Android docs for more information.

Upvotes: 2

Related Questions