Skip to content Skip to sidebar Skip to footer

How To Convert Given Date Into Readable Format In Android

I am doing Json parsing and retrieving a Date from it. I am getting in this format 2012-07-24 but i want to display it in this format Tuesday July 24, 2012. Can anybody suggest how

Solution 1:

You can use SimpleDateFormat to parse and format the date. On the JavaDoc are lots of examples: http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

Solution 2:

Use

String s;
Format formatter;
                  //  vvvvvvvvvv  Add your date object here
Datedate=newDate("2012-07-24");

formatter =new SimpleDateFormat("EEEE MMMM dd, yyyy");
s = formatter.format(date);
System.out.println(s);

Solution 3:

You can try

Stringdate="2012-07-24";
    try {
        SimpleDateFormatformat=newSimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormatdf2=newSimpleDateFormat("EEE MMM dd, yyyy");
        date = df2.format(format.parse(yourdate));
    } catch (java.text.ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Solution 4:

use this below method

SimpleDateFormat dfDate  = newSimpleDateFormat("yyyy-MM-dd");
 SimpleDateFormat dfDate_day= newSimpleDateFormat("EEEE MMMM dd, yyyy");

 publicStringformatTimeDay(String str)
 {
    java.util.Date d = null;

    try {
        d = dfDate.parse(str);
    } catch (java.text.ParseException e) {
        e.printStackTrace();
    }
    str = dfDate_day.format(d);

    return str;
}

usage ====> formatTimeDay("2012-07-24");

Here

EEEE =====> day name (like Sunday, Monday)
MMMM =====> month name(like January, March)
dd   =====> day number of the present month
yyyy =====> present year

Solution 5:

You need to use SimpleDateFormat for this purpose, do as follows:

SimpleDateFormat smf=newSimpleDateFormat("yyyy-MM-dd");
Date dt=smf.parse(strDate, 0);
smf= newSimpleDateFormat("EEEE MMMM dd,yyyy");
String newFt=smf.format(dt);

Post a Comment for "How To Convert Given Date Into Readable Format In Android"