js獲取時間(yyyy-MM-dd HH:mm:ss)


/**
   *  獲取當前時間
   *
   * @return 返回時間類型 yyyy-MM-dd HH:mm:ss
   */
function sysTime(){
 
var myDate = new Date();
 
var year = myDate.getFullYear();
 
var month = myDate.getMonth()+1;
 
var date = myDate.getDate();
 
var h = myDate.getHours();
 
var m = myDate.getMinutes();
 
var s = myDate.getSeconds();
 
var now = year + '-' + getMakeZero(month) + "-" + getMakeZero(date) + " " + getMakeZero(h) + ':' + getMakeZero(m) + ":" + getMakeZero(s);
 
return now;
}
 
/**
   *  時間補0
   *
   * @return 返回時間類型 yyyy-MM-dd HH:mm:ss
   */
function getMakeZero(s) {
 
    return s < 10 ? '0' + s : s;
}
 
小白一枚,勤於整理,多多指教。
轉載請注明來源,感謝合作。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM