UTCformat 转换UTC时间并格式化成本地时间


/**
   * UTCformat 转换UTC时间并格式化成本地时间
   * @param {string} utc
   */
  UTCformat (utc) {
    var date = new Date(utc),
        y = date.getFullYear(),
        month = date.getMonth()+1 > 9 ? date.getMonth()+1 : '0' + parseInt(date.getMonth()+1),
        day = date.getDate() > 9 ? date.getDate() : '0' + date.getDate(),
        h =  date.getHours() > 9 ? date.getHours() : '0' + date.getHours(),
        m = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes(),
        s = date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds();
    var res = y + '-' + month + '-' + day + ' ' + h + ':' + m;
    return res;
  }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM