2017-06-21 8 views

答えて

0

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); 
0

同じ日の別の発生(水曜日が来るまで)または月が終了するまで、ユーザーがループを実行するカレンダーの日(水曜日)を取得します。

関連する問題