Last active
May 6, 2017 10:12
-
-
Save myfreeer/2dcda6e49fff0e0ab9e114c8cfa92045 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 str2sec = str => str.split(':').reduce((acc, val)=>Number(acc)*60 + Number(val)); | |
const sec2str = t => t/60|0 > 0 ? sec2str(t/60|0) + ':' + t%60 : t + ''; | |
//demo below | |
var timeStr = '3:44:45.466'; // 3 hour, 44 min, 45 sec, 466 ms | |
var timeSec = str2sec(timeStr); // 13485.466 sec | |
sec2str(timeSec); // "3:44:45.46600000000035" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment