日期比较javascript

日期比较javascript,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 1

下一种方式的字符串比较可靠吗?换句话说,这种比较在内部是如何工作的

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!');
var_date=新日期();
var\u start\u date=\u date.getFullYear()+“-”+\u date.getMonth()+“-”+\u date.getDate()+“-”+\u date.getHours+“-”+\u date.getMinutes();
如果(开始日期<“2011-1-11-23-59”)
警报(“仍然在1月11日之前!”);

上面的操作非常完美,但是javascript比较是如何做到这一点的呢?我知道我可以根据历元和/或新日期()进行计算,但在我的情况下,这是不可能的。

这对我来说似乎更好:

  if (new Date() < new Date("January 11, 2011 00:00:00"))
     alert('still before the 11th of january!');
if(新日期()


Hogan,的确如此,但要注意时间和分钟。在上述情况下,这确实不清楚。时间和分钟对我来说非常重要。仅供参考:我还有一个基于“开始日期”<“日期”&&&“结束日期”>“日期”的条件,我为您添加了它们--有一种格式--即午夜,使用24小时时钟。(在测试中,我刚刚做的14:00:00是当地时间下午2点)在这种情况下,您可以使用if(new Date()