I have date picker in my application and its works well .But I need selected day of week instead of date (i.e., if I select the date 23 I need to get day like \"friday\" ins
Don't use:
Date date = new Date(selectedYear, selectedMonth, selectedDay-1);
It is deprecated and will give wrong output in some cases. Check with 28-jan-2015 and 04-jul-1940, both are Thursday but it returns Friday for 04-jul-1940.
Use:
GregorianCalendar GregorianCalendar = new GregorianCalendar(year, monthOfYear, dayOfMonth-1);
int dayOfWeek=date.get(date.DAY_OF_WEEK);
The above method will return an integer value:
This will give u the day names::
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
Date d_name = new Date();
String dayOfTheWeek = sdf.format(d_name);
change your code as for getting day of week using SimpleDateFormat
:
private DatePickerDialog.OnDateSetListener
datePickerListener = new DatePickerDialog.OnDateSetListener()
{
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay)
{
SimpleDateFormat simpledateformat = new SimpleDateFormat("EEEE");
Date date = new Date(selectedYear, selectedMonth, selectedDay-1);
String dayOfWeek = simpledateformat.format(date);
}
}