2017-03-20 14 views
-3

我要檢查,如果今天的日期比規定日期更大的發言權2017年3月26日 注只有一個日期指定不是我無論在堆棧溢出的問題,回答兩個之間檢查研究其他特定日期更大指定日期。 我要檢查檢查我當前日期是不是JavaScript

if(current date > specified date) { 
// do this 
} 

我試圖轉換爲一天,但它是不靈活。我理解力以及

+1

可能複製http://stackoverflow.com/q/492994/6568620 –

+0

我在寫的問題其他答案比較兩個指定日期不是當前日期與其他指定日期的ü回答 –

+0

思前想@RishabhAhuja我想你應該仔細閱讀答案新日期();會給你當前的日期由穆罕默德·阿巴斯的鏈接就足夠了,收你的答案 –

回答

1

使用Moment.js處理日期,

例如:

moment().isAfter('2014-03-26T01:14:00Z') // true 
moment().isAfter('2017-03-26T01:14:00Z') // false 
1

var specific_date = new Date('2017-03-26'); 
 
var current_date = new Date(); 
 
if(current_date.getTime() > specific_date.getTime()) 
 
{ 
 
    console.log('current_date date is grater than specific_date') 
 
} 
 
else 
 
{ 
 
    console.log('current_date date is lower than specific_date') 
 
}

1

其中一個解決方案,我建議的是moment.js庫。

它提供像isBefore(),isSame()和isAfter查詢功能()。

var today = moment('2010-10-20'), 
 
    specifiedDate = moment('2010-10-21'); 
 
if(today.isBefore(specifiedDate)){ 
 
    console.log("Past Date"); 
 
}else{ 
 
    console.log("Future Date"); 
 
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.0/moment.min.js"></script>

相關問題