2017-06-21 60 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

獲取日曆的日期(例如星期三),用戶在其中運行一個循環,直到您獲得同一天的另一個事件(直到週三再次到來)或月份結束。

相關問題