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