+ 2

How to find differences between two times

Time must be in 24 hour format

15th Feb 2021, 5:19 AM
shona kanojiya
3 Respostas
+ 3
Okk thanku so much
15th Feb 2021, 5:43 AM
shona kanojiya
15th Feb 2021, 5:30 AM
A͢J
A͢J - avatar
+ 2
Let's assume that hours, minutes and seconds are different variables with numbers (not text). Then: time1 = hours1 * 3600 + minutes1 * 60 + seconds1 time2 = hours2 * 3600 + minutes2 * 60 + seconds2 difference = (time1 - time2) % 86400 Hope you understood the formula and now can write the code by this formula! (Tip: in JavaScript time1_or_2 = new Date("1970-01-01T" + window.prompt('Time (format: "hh:mm:ss")') + "Z"), where 1970-01-01 is just the first day in Unix time, T tells that there will be time and Z tells that timezone is default. Created objects have getSeconds(), getMinutes() and getHours() methods) If you asked for the complete code, then we cannot help you: SoloLearn is not a community of "Write X => Here is the implementation of X in Y".
15th Feb 2021, 5:41 AM
#0009e7 [get]
#0009e7 [get] - avatar