jquery之獲取當前時間和月份加1


jquery之獲取當前時間

/**
 * 
 * 獲取當前時間
 */
function p(s) {
    return s < 10 ? '0' + s: s;
}

var myDate = new Date();
//獲取當前年
var year=myDate.getFullYear();
//獲取當前月
var month=myDate.getMonth()+1;
//獲取當前日
var date=myDate.getDate(); 
var h=myDate.getHours();       //獲取當前小時數(0-23)
var m=myDate.getMinutes();     //獲取當前分鍾數(0-59)
var s=myDate.getSeconds();  

var now=year+'-'+p(month)+"-"+p(date)+" "+p(h)+':'+p(m)+":"+p(s);

如果需要月份加1的話

var myDate2 = new Date();
myDate2.setMonth(month + 1);

//獲取當前年
var year2=myDate2.getFullYear();
//獲取當前月
var month2=myDate2.getMonth();
//獲取當前日
var date2=myDate2.getDate();

var now2=year2+'-'+p(month2)+"-"+p(date2);

 


免責聲明!

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



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