0
How to sum java.sql.Time ?
How to get total? Time t1 = new Time(08:00:00); Time t2 = new Time(09:00:00); Time total = 17:00:00
5 Respuestas
+ 1
An example how you can add multiple durations.
https://code.sololearn.com/cj20iaRbo9qJ/?ref=app
+ 3
You cannot create time objects like that, your code won't work.
Also, don't use java.sql.Time if at all possible. java.time.LocalTime is more modern and has much better methods. If you insist on sql.Time then you can also convert it to LocalTime and back.
The following example converts both Time objects to nanoseconds (a long value) to add them, and then convert it back to Time.
https://code.sololearn.com/c5TOL75zQBfF/?ref=app
0
it does not work for me.
0
Time time1 = “08:00:00”;
Time time2 = “17:00:00”;
//time1 and time2 is java.sql.Time
error:
invalid value for NonaofDay (valid value 0 - 86399
i think it is more than 24 hours and so dose not work.
how can get sum multiple times in for loop?
ex:
//time is java.sql.Time
Time time;
for(int i=0;i<30;i++){
time += time1.gettime();
}
0
In your original example you had 8+9=17 hours so that worked.
You cannot add Time objects to each other. It is designed to represent a specific time of day.
To work with durarions, I suggest to read this.
https://docs.oracle.com/javase/tutorial/datetime/iso/period.html