Created
June 27, 2019 17:37
-
-
Save louismanson/12e676810c28b46abfe4c859a3f66fde to your computer and use it in GitHub Desktop.
seconds to ISO 8601
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
let segToIso8601 = (duaration) => { | |
let hours; | |
let minutes; | |
let seconds; | |
let result; | |
if(duaration>3600){ | |
hours = Math.floor(duaration/3600)+"H"; | |
let min = Math.floor(duaration%3600); | |
if(min>60){ | |
minutes = Math.floor(min/60)+"M"; | |
let seg = Math.floor(min%60); | |
if(seg>0){ | |
seconds = seg+"S"; | |
} | |
} | |
result = "PT" + hours + minutes + seconds; | |
}else{ | |
if(duaration>60){ | |
minutes = Math.floor(duaration/60)+"M"; | |
let seg = Math.floor(duaration%60); | |
if(seg>0){ | |
seconds = seg+"S"; | |
} | |
result = "PT" + minutes + seconds; | |
}else{ | |
if(duaration>0){ | |
seconds = seg+"S"; | |
} | |
result = "PT" + seconds; | |
} | |
} | |
return result | |
} | |
console.log(segToIso8601(935)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment