簡體   English   中英

使用jQuery進行日期比較

[英]Date comparison using jquery

我使用以下代碼檢查日期是否在今天之前! 但是當我今天選擇時,條件變為真!

var fromDate = $('#from').datepicker('getDate');
var toDate = $('#to').datepicker('getDate');
var today = new Date();

if(today >= fromDate || toDate <= today){
    alert('Cannot book dates prior to today.');
    $('#from, #to').val('')
    return false;
}

我在這里做錯了什么?

應該是這樣的

var fromDate = $('#from').datepicker('getDate');
var toDate = $('#to').datepicker('getDate');
var today = new Date();
 today.setHours(0,0,0,0);
fromDate.setHours(0,0,0,0);
toDate.setHours(0,0,0,0);

if(today > fromDate || toDate < today){
    alert('Cannot book dates prior to today.');
    $('#from, #to').val('')
    return false;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM