简体   繁体   中英

Android datePicker get day of week

How to retrieve the next Saturday from current date datepicker this is my problem

Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

Try this

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
calendar.set(Calendar.MONTH, datePicker.getMonth());
calendar.set(Calendar.YEAR, datePicker.getYear());

int day = calendar.get(Calendar.DAY_OF_WEEK);//Try this

The variable day contains 1 for SUNDAY , 2 for TUESDAY and so on...

Hope this helps. Feel free to ask for clarifications...

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
calendar.set(Calendar.MONTH, datePicker.getMonth());
calendar.set(Calendar.YEAR, datePicker.getYear());

while(calendar.get(Calendar.DAY_OF_WEEK) != 1) {
    calendar.add(Calendar.DATE, 1);
}
String nextSunday = calendar.getTime().toString();

you will find upcoming Sunday date.. nextSunday string format be like "Sun Mar 16 02:13:28 EET 2012"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM