Add two hours in Java

1

I'm using java and I have the following scenario.

The entity season one of the attributes is duration and a season can have many chapters, for each chapter that is added to a season, the duration of all the chapters is added and added to the season.

I am doing the following:

 res.getTemporada().setDuracion(res.getTemporada().getDuracion() +  res.getDuracion());

To the duration of the season:

res.getTemporada().getDuracion()

I add the duration that I bring from the view of the new chapter, but the sum in this conventional way does not work

res.getDuracion()

The duration is of the Time type

    
asked by Juan Pablo B 07.11.2018 в 20:30
source

1 answer

4

The truth is that class Time is not suitable for the use you are giving it. While time means time, the correct translation for its use would be time.

For example, a class Time can not reflect a duration that exceeds 24 hours.

To save the duration of the chapters of a series a convenient measure can be the minutes that last, and that can accumulate quietly in a int . For example 80hs would be 80*60 = 4800 minutos .

Then you can use a function that returns time as String by doing the reverse step. For example 4826 minutos are:

int hh = (int)(4826 / 60); // 80
int mm = 4826 % 60;  // los 26 minuto adicionales de la fracción

And you can show it as: String.format("%02d:%02d", hh, mm);

    
answered by 08.11.2018 / 04:30
source