jQuery 時(shí)間操作

//獲取當(dāng)前時(shí)間:
  var myDate = new Date();//當(dāng)前時(shí)間
  var year = myDate.getFullYear();//當(dāng)前年份
  var month = myDate.getMonth() + 1;//當(dāng)前月份
  var day = myDate.getDate();//當(dāng)前日
  myDate.getYear();        //獲取當(dāng)前年份(2位)
    myDate.getFullYear();    //獲取完整的年份(4位,1970-????)
    myDate.getMonth();       //獲取當(dāng)前月份(0-11,0代表1月)
    myDate.getDate();        //獲取當(dāng)前日(1-31)
    myDate.getDay();         //獲取當(dāng)前星期X(0-6,0代表星期天)
    myDate.getTime();        //獲取當(dāng)前時(shí)間(從1970.1.1開(kāi)始的毫秒數(shù))
    myDate.getHours();       //獲取當(dāng)前小時(shí)數(shù)(0-23)
    myDate.getMinutes();     //獲取當(dāng)前分鐘數(shù)(0-59)
    myDate.getSeconds();     //獲取當(dāng)前秒數(shù)(0-59)
    myDate.getMilliseconds();    //獲取當(dāng)前毫秒數(shù)(0-999)
    myDate.toLocaleDateString();     //獲取當(dāng)前日期
    var mytime=myDate.toLocaleTimeString();     //獲取當(dāng)前時(shí)間
    myDate.toLocaleString( );        //獲取日期與時(shí)間
  var oneDay = 1000 * 60 * 60 * 24;
//獲取最近一周的日期
  var lastDate = new Date(myDate - oneDay * 6);
  var lastYear = lastDate.getFullYear();
  var lastMonth = lastDate.getMonth() + 1;
  var lastDay = lastDate.getDate();
//獲取當(dāng)前月的最后一天
  var day = new Date(year ,month , 0);
  var lastdate = day.getDate();//當(dāng)前月的最后一天
//獲取最近N個(gè)月的日期   
   var lastDate = new Date(myDate - oneDay * myDate.getDate());
   lastDate = new Date(lastDate - N * oneDay * (lastDate.getDate() - 1));
   var lastYear = lastDate.getFullYear();
   var lastMonth = lastDate.getMonth() + 1;
   var lastDay = lastDate.getDate();
//字符串轉(zhuǎn)換為時(shí)間戳
   var date="2014-05-08 00:22:11";
   date = new Date(Date.parse(date.replace(/-/g, "/")));
   date = date.getTime();
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容