簡體   English   中英

JavaScript檢查日期不是今天或過去

[英]JavaScript Check Date not today or in the past

JavaScript Check Date不是今天或過去。

var c = '10 JUN 2010'; // this is the format of the date coming in.
var temp = new Array();
temp = c.split(' ');

var x = new Date ( temp[1]+" "+temp[0]+", "+temp[2] );

if (x.getTime() > getDate()) {
   alertstring = alertstring + '\n\nDEBUG CODE: 1 ' + x + '\n\n';
}

我無法更改進來的格式。

看起來您99%擁有它。 這是經過修改的if條件:

var c = '10 JUN 2010'; // this is the format of the date coming in.
var temp = new Array();
temp = c.split(' ');

var x = new Date ( temp[1]+" "+temp[0]+", "+temp[2] );

if (x.getTime() > (new Date().getTime())) {
    ...
}

更新此行:

// Get current date and time
var today = new Date();

// strip time to compare to the parse date
if (x.getTime() > new Date(today.getFullYear(), today.getMonth(), today.getDate()).getTime()) {
    // this date has not happened yet.
    alertstring = alertstring + '\n\nDEBUG CODE: 1 ' + x + '\n\n';
}

嘗試在構造函數中輸入月份數而不是string。 而不是六月放6。

暫無
暫無

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

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