js時間函數


//獲取今天的日期和時間
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();//當前秒(0-59)

   //獲取明天的日期

   var tomorrow = new Date();

   tomorrow.setTime(tomorrow.getTime() + 24*60*60*1000);

   tomorrow_month = tomorrow.getMonth()+1;//月

 tomorrow_date =  tomorrow.getDate();//日

//獲取當前時間戳
var now_timestamp = myDate.getTime();

//獲取指定時間的時間戳

var time = new Date( year, myDate.getMonth(), date, h, m, s);
var timestamp = time.getTime()

//比較兩個時間的大小(先后)
if(now_timestamp > timestamp){
alert('當前時間大');
}


免責聲明!

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



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