-1
月の特定の週の開始日と終了日を取得したい場合 たとえば、開始日よりもカレンダーの画像は1/FEB/2017、終了日は4/FEB/2017になります。ありがとう。 開始日と終了日を月から1週間(アンドロイド)から取得したい場合
月の特定の週の開始日と終了日を取得したい場合 たとえば、開始日よりもカレンダーの画像は1/FEB/2017、終了日は4/FEB/2017になります。ありがとう。 開始日と終了日を月から1週間(アンドロイド)から取得したい場合
Calendar calendar = Calendar.getInstance();
Date date1 = calendar.getTime();
//current date to check that our week lies in same month or not
SimpleDateFormat checkformate = new SimpleDateFormat("MM/yyyy");
String currentCheckdate= checkformate.format(date1);
int weekn = calendar.get(Calendar.WEEK_OF_MONTH);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
//resat calender without date
calendar.clear();
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.set(Calendar.WEEK_OF_MONTH,weekn);
calendar.set(Calendar.MONTH,month);
calendar.set(Calendar.YEAR,year);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date datef = calendar.getTime();
//move date to 6 days + to get last date of week
Long timeSixDayPlus = calendar.getTimeInMillis()+518400000L;
Date dateL = new Date(timeSixDayPlus);
String firtdate = simpleDateFormat.format(datef);
String lastdate = simpleDateFormat.format(dateL);
String firtdateCheck = checkformate.format(datef);
String lastdateCheck = checkformate.format(dateL);
//if our week lies in two different months then we show only current month week part only
if (!firtdateCheck.toString().equalsIgnoreCase(currentCheckdate)) {
firtdate = "1" + "/" + calendar.get(Calendar.MONTH) + "/" + calendar.get(Calendar.YEAR);
}
if (!lastdateCheck.toString().equalsIgnoreCase(currentCheckdate)) {
int ma = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
lastdate = String.valueOf(ma) + "/" + calendar.get(Calendar.MONTH) + "/" + calendar.get(Calendar.YEAR);
}
Log.e("current","=>>"+firtdate+" to "+lastdate);
同じ日の別の発生(水曜日が来るまで)または月が終了するまで、ユーザーがループを実行するカレンダーの日(水曜日)を取得します。
月曜日と日曜日をチェックしてください –