JavaScript 检查日期不是今天或过去

标签 javascript

JavaScript 检查日期不是今天或过去。

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())) {
    ...
}

关于JavaScript 检查日期不是今天或过去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7421988/

相关文章:

javascript - 以 react 形式将 firebase.firestore.timestamp 转换为数据的 patchValue 之前的日期

javascript - 引导箱验证

javascript - 为什么在 Div 中重复添加新元素时得到 `HierarchyRequestError`?

javascript - ng-repeat 对象中的自动增量

javascript - 在 three.js 中更改 gridhelper 的宽度和高度?

javascript - 循环遍历包含另一个表单的表单

javascript - 在 Liferay 5.2.3 中禁用 JavaScript minifier 时出现问题

javascript - javascript 所需的总数

javascript - Response.Redirect(Request.RawUrl) 之后的 Response.Write

javascript - 使用 jSTL 自动检查单选按钮