比较日期时间当前日期javascript
我有txtStartDate控件那样的格式:09.03.2012比较日期时间当前日期javascript
我想比较txtStartDate的值CurrentDate。如果txtStartDate比CurrentDate大,我想返回true。如何做到这一点?
日期在JavaScript中吸吮。我建议使用这个库FWIW,http://www.datejs.com/
具体http://code.google.com/p/datejs/wiki/APIDocumentation#compare
及相关
另见
http://code.google.com/p/datejs/wiki/APIDocumentation#parse文本实际上转换为Date对象。
你要创建你的文本Date对象。这可能会涉及以字符串和分裂它,并把它传递给Date(year, month, day)
构造。我无法分辨你的日子和月份,所以我不能给你示例代码。
一旦你创建了一个Date对象,你可以把它比作当前的日期,你可以开始使用new Date()
。
反向日期:20120309
,比较容易。
function chgDate(dte){
var pm=new String(dte.getMonth()+1);if(pm.length<2) pm='0'+pm;
var pd=new String(dte.getDate());if(pd.length<2) pd='0'+pd;
var py=dte.getFullYear();
return new Number(py+pm+pd);
}
function chgControl(dte){
dte=dte.split('.');
return new Number(dte[2]+dte[1]+dte[0]);
}
bool=(chgControl('09.03.2012')>chgDate(new Date()));
或只是.getTime(),这仍然不能解决解析格式为日期。 – 2012-03-07 10:07:17
@j_mcnally现在解析日期。 – Teemu 2012-03-07 10:25:27
http://*.com/questions/1576753/parse-date-string-in-javascript – Behrang 2012-03-07 10:06:45