Search code examples
javaandroiddatesimpledateformat

Get value of day month from Date object in Android?


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.


Solution

  • 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