+ 2
How to find differences between two times
Time must be in 24 hour format
3 Antworten
+ 3
Okk thanku so much
+ 2
shona kanojiya
Check this code in JS
https://code.sololearn.com/Wro99TiF1nkR/?ref=app
+ 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".