js獲取當前時間

function getCurrentDate() {
    var now = new Date();
    var year = now.getFullYear(); //獲得年份
    var month = now.getMonth();//獲得月份
    var date = now.getDate();//獲得日期
    var day = now.getDay();//獲得周幾
    var hour = now.getHours();//獲得小時
    var minu = now.getMinutes();//獲得分鐘
    var sec = now.getSeconds();//獲得秒

    month = month + 1;
    if (month < 10) month = "0" + month;
    if (date < 10) date = "0" + date;
    if (hour < 10) hour = "0" + hour;
    if (minu < 10) minu = "0" + minu;
    if (sec < 10) sec = "0" + sec;
    var time = year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;

    return time;
  }

原文:http://www.cicis.com.cn/16e8f5fc0d4a49fea5babc96ede71bf8code

相關文章
相關標籤/搜索