Created
May 17, 2018 02:13
-
-
Save loskael/6726315d47e10c42135097af7ef28ccd to your computer and use it in GitHub Desktop.
计算时针和分针的夹角
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const angle = (time = '00:00') => { | |
let [hour, minute] = time.split(':').map(v => parseInt(v, 10)); | |
hour += minute / 60; | |
let ah = (360 / 12) * (hour % 12); | |
let am = (360 / 60) * minute; | |
let diff = Math.abs(ah - am); | |
return diff > 180 ? 360 - diff : diff; | |
}; | |
[ | |
'00:00', '12:00', '00:30', | |
'01:00', '13:00', | |
'02:00', | |
'03:00', | |
'04:00', | |
'05:00', | |
'06:00', '06:30', | |
'07:00', | |
'08:00', '08:20', | |
'09:00', | |
'10:00', | |
'11:00', | |
].forEach(v => console.log(v, angle(v))); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment