[英]How to I get the list of week days for a specific date in android
I'm implementing the material calendar view in android app,the user can select a particular date in the calendar.how do i get the complete list of week days for that particular selected date 我正在Android应用程序中实现物料日历视图,用户可以在Calendar中选择一个特定的日期。如何获取该特定所选日期的工作日的完整列表
for example: if user selects 22 as the date,how do i get the week days in that row from calendar in which 22 is present 例如:如果用户选择22作为日期,我如何从存在22的日历中获取该行中的工作日
Your requirement is unclear. 您的要求不清楚。 If you want to get the week day for that day, you can use
Calendar.getInstance().set(year, month, day); int dayOfWeek = Calendar.getInstance().DAY_OF_WEEK;
如果要获取当天的工作日,则可以使用
Calendar.getInstance().set(year, month, day); int dayOfWeek = Calendar.getInstance().DAY_OF_WEEK;
Calendar.getInstance().set(year, month, day); int dayOfWeek = Calendar.getInstance().DAY_OF_WEEK;
Ref : https://developer.android.com/reference/java/util/Calendar.html 参考: https : //developer.android.com/reference/java/util/Calendar.html
try this 尝试这个
public String[] getWeekDaySelected(String selectedDateStr) {
Calendar cal = Calendar.getInstance();
try {
Date startDate = sdf.parse(sdf.format(cal.getTime()));
Date endDate = sdf.parse(selectedDateStr);
weekDaysCount = Functions.getWeeksBetween(startDate, endDate);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String[] days = new String[7];
// set the011, 10 - 1, 12);
String[] arr = selectedDateStr.split("-");
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(arr[2]));
cal.set(Calendar.MONTH, (Integer.parseInt(arr[1]) - 1));
cal.set(Calendar.YEAR, Integer.parseInt(arr[0]));
Calendar first = (Calendar) cal.clone();
first.add(Calendar.DAY_OF_WEEK, first.getFirstDayOfWeek() - first.get(Calendar.DAY_OF_WEEK));
first.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// and add six days to the end date
Calendar last = (Calendar) first.clone();
last.add(Calendar.DAY_OF_YEAR, 6);
// print the result
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(first.getTime()) + " -> " +
df.format(last.getTime()));
for (int i = 0; i < 7; i++) {
days[i] = format.format(first.getTime());
first.add(Calendar.DAY_OF_MONTH, 1);
}
return days;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.