Generate a cycle to add days to a date

0

Good morning I am trying to add a few days to days without counting Saturdays and Sundays when it gets to Friday, the day increases but the result is Saturday afterwards it does not do anything for the condition of the if ():

while (dias<=num_dias_afectar) 
         {

            if (fechaInicialcalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && fechaInicialcalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) 
                {

                    fechaInicialcalendar.add(Calendar.DATE, 1);
                    Date fecha_fin = fechaInicialcalendar.getTime();
                    fecha_termino = format.format(fecha_fin);
                    dias++;

                }

        } 

How can I prevent the result from being Saturday or in other cases the result is Monday?

    
asked by David Melo 08.03.2018 в 18:49
source

1 answer

0

Solved:

 while (dias<=num_dias_afectar) 
         {

            if (fechaInicialcalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && fechaInicialcalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) 
                {       

                        Date fecha_fin = fechaInicialcalendar.getTime();
                        fecha_termino = format.format(fecha_fin);
                        dias++;    
                }
            fechaInicialcalendar.add(Calendar.DATE, 1);       
        }  
    
answered by 08.03.2018 / 19:13
source