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

Pooja Dubey
  • 683
  • 2
  • 14
  • 34

3 Answers3

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()));
    }
Developer
  • 6,292
  • 19
  • 55
  • 115
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)
Avijit
  • 3,834
  • 4
  • 33
  • 45
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);
Dima
  • 1,490
  • 16
  • 25