0

I am using calender in my app and i want to change the format of the date.

private void updateLabel() {
        String myFormat = "dd/MM/yy"; // In which you need put here
        SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

            checkin_date.setText(sdf.format(myCalendar.getTime()));


    }

I want this format Fri, 21 Nov 2013

How can we do this .Please help me in this

4

3 回答 3

1

Here in the Update that you need to do

private void updateLabel() {
        String myFormat = "EEE,dd-MM-yyyy"; // In which you need put here
        SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
        checkin_date.setText(sdf.format(myCalendar.getTime()));
    }
于 2013-11-18T06:56:55.863 回答
0

Try this:

SimpleDateFormat sourceFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
SimpleDateFormat desiredFormat =new SimpleDateFormat("EEE,dd-MMM-yyyy");    
Date dt = sourceFormat.parse(your_date);
String desiredDateString = desiredFormat.format(dt)
于 2013-11-18T06:43:09.933 回答
0

You can use method:

private String changeFormat(String unformattedDate, SimpleDateFormat formatFrom, SimpleDateFormat formatTo) {
    if (TextUtils.isEmpty(unformattedDate)) {
        return "";
    }
    try {
        Date date = formatFrom.parse(unformattedDate);
        return formatTo.format(date);
    } catch (ParseException e) {
        throw new IllegalArgumentException(String.format("Date '%s' has incorrect format", unformattedDate));
    }
}

Example:

SimpleDateFormat formatFrom = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat formatTo = new SimpleDateFormat("EEE, dd MMM yyyy");
String sourceDate = "18/11/2013";
String desiredDate = changeFormat(sourceDate, formatFrom, formatTo);
于 2013-11-18T07:01:17.370 回答