1 个回答

俗语道,自己动手,丰衣足食。

/*
 * transform the time from the int(0) form to the string("00:00") form 
 * @param {int} unformTime:the int form time
 * @return {string} formedTime:the string form time("00:00")
 */
//need to be checked(efficiency)
function transformTime(unformedTime) {
    var formedTime = "";
    if (isNaN(unformedTime) || (unformedTime == Infinity) || (unformedTime<0)) {
        formedTime = "00:00"
    } else {
        var minutes = Math.floor(unformedTime / 60);
        if (minutes < 10) {
            minutes = "0" + minutes;
        }
        var seconds = Math.floor(unformedTime - minutes * 60);
        if (seconds < 10) {
            seconds = "0" + seconds;
        }
        formedTime = minutes + ":" + seconds;
    }
    return formedTime;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题