Sum of times | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Sum of times

how can get sum multiple times in for loop? ex: Time time1 = “08:00:00”; Time time; //time and time 1 are java.sql.Time for(int i=0;i<30;i++){ time += time1.gettime(); }

10th Sep 2020, 12:00 PM
hamid
hamid - avatar
3 Answers
+ 1
hamid In that case you don't want to use Time object, because it represents real time, hence maximum value can be 23:59:59. If you add one more second to that you will receive 00:00:00. Use integers to count working hours.
11th Sep 2020, 7:43 AM
Aleksandrs
Aleksandrs - avatar
0
Why do you want to sum times? It's pointless. It's like, what will be a sum of 1st of July 1985 and 23 of March 2020? A complete nonsense. If you want to increment time, you can use LocalTime object and plusHours() or plus(duration) methods.
10th Sep 2020, 3:51 PM
Aleksandrs
Aleksandrs - avatar
0
i want to know how many times i was in work in month. so i need to sum all times.
11th Sep 2020, 7:39 AM
hamid
hamid - avatar