日期比较javascript
问题描述:
下一步的字符串比较可靠吗?换句话说,这种比较如何在内部起作用?日期比较javascript
var _date = new Date();
var _start_date = _date.getFullYear()+"-"+_date.getMonth()+"-"+_date.getDate()+"-"+_date.getHours+"-"+_date.getMinutes();
if(_start_date < "2011-1-11-23-59")
alert('still before the 11th of january!');
上面的工作完美,但javascript比较如何工作这种方式?我知道我可以计算基于EPOCH和/或新的日期(),但在我的情况下,这是不可能的。
答
这似乎更好地对我说:
if (new Date() < new Date("January 11, 2011 00:00:00"))
alert('still before the 11th of january!');
见
和
霍根,没错确实,但介意小时和分钟。在上述情况下,这确实不明确。小时和分钟对我而言非常重要。 Fyi:我还有一个基于_start_date “date”的条件 – Grezly 2011-01-06 18:13:42