2017-02-25 36 views
1

那是我的倒計時代碼。我想知道如何從我的代碼中排除星期五或星期六的examlpe。提前致謝。如何排除我倒計時的星期五

 public void run() { 
      handler.postDelayed(this, 1000); 
      try { 
       SimpleDateFormat dateFormat = new SimpleDateFormat(
         "yyyy-MM-dd"); 
       // Event Date 
       Date futureDate = dateFormat.parse("2017-4-2"); 
       Date currentDate = new Date(); 
       if (!currentDate.after(futureDate)) { 
        long diff = futureDate.getTime() 
          - currentDate.getTime(); 
        long days = diff/(24 * 60 * 60 * 1000); 
        diff -= days * (24 * 60 * 60 * 1000); 
        long hours = diff/(60 * 60 * 1000); 
        diff -= hours * (60 * 60 * 1000); 
        long minutes = diff/(60 * 1000); 
        diff -= minutes * (60 * 1000); 
        long seconds = diff/1000; 

其餘代碼被刪除。

+0

請提供完整信息 –

回答

0

只看看有多少星期五或星期六在那裏,並從倒數中減去它們。

0
//Plain java 
    Calendar calendar = Calendar.getInstance(); 
    //The date that you want to check 
    calendar.setTime(currentDate); 
    //Filter Friday and Saturday 
    if(!calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY 
      && !calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY){ 
     //process the date 
    } 


    //Using Joda time 
    LocalDate theDate= new LocalDate(2016, 11, 12); //12 Nov 2016 
    int dayOfTheWeek = theDate.dayOfWeek().get(); //an integer, representing the day of the week 

    if (!DateTimeConstants.FRIDAY== dayOfTheWeek 
       &&!DateTimeConstants.SATURDAY== dayOfTheWeek) { 

    } 
相關問題