javascript与php时/分/秒与秒数互转

  1. javascript:
    /*
    时间转换成秒
    */
    function time_to_second(time){
    var arr = time.split(':')
    var hour = arr[0]?arr[0]:0
    var minute = arr[1]?arr[1]:0
    var second = arr[2]?arr[2]:0
    var ret = hour * 3600 + minute * 60 + second
    return ret
    }
    /*
    秒转换成时间
    */
    function second_to_time(seconds){
    hour = Math.floor(seconds / 3600)
    minute = Math.floor((seconds - hour * 3600) / 60)
    second = seconds - hour * 3600 - minute * 60
    if(hour < 10){
        hour = "0" + hour
    }
    if(minute < 10){
        minute = "0" + minute
    }
    if(second < 10){
        second = "0" + second
    }
    ret = hour + ':' + minute + ':' + second
    return ret
    }
    // var time = "10:00:00"
    // var ret = time_to_second(time)
    // console.log(ret)
    var seconds = 36000
    var ret = second_to_time(seconds)
    console.log(ret)
  2. php:

分享名称:javascript与php时/分/秒与秒数互转
URL标题:http://lszwz.com/article/jsihds.html

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款