Get value of day month from Date object in Android?

NRahman picture NRahman · Jun 19, 2013 · Viewed 83.5k times · Source

By using this code :

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = format.parse(dtStart);
return date;

I have converted the String Date by Date Object and get the value:

Sun Feb 17 07:00:00 GMT 2013

Now I want to extract day (Sunday/Monday) and month from here.

Answer

Pankaj Kumar picture Pankaj Kumar · Jun 19, 2013
import android.text.format.DateFormat;

String dayOfTheWeek = (String) DateFormat.format("EEEE", date); // Thursday
String day          = (String) DateFormat.format("dd",   date); // 20
String monthString  = (String) DateFormat.format("MMM",  date); // Jun
String monthNumber  = (String) DateFormat.format("MM",   date); // 06
String year         = (String) DateFormat.format("yyyy", date); // 2013