简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM