我编写了以下脚本来比较时间:
var TC1WarningTime = new Date(2013, 6-1, 30, 4),
TC1WarningTimeformat = [TC1WarningTime.getDate(),
(TC1WarningTime.getMonth()+1),
TC1WarningTime.getFullYear()].join('/')+
' ' +
[TC1WarningTime.getHours().padLeft()]+'HKT';
var TC1ReportTime = new Date(2013, 6-1, 30, 3),
TC1ReportTimeformat = [TC1ReportTime.getDate(),
(TC1ReportTime.getMonth()+1),
TC1ReportTime.getFullYear()].join('/')+
' ' +
[TC1ReportTime.getHours().padLeft()]+'HKT';
var TC1CurrentTime = "";
if (TC1WarningTime>TC1ReportTime) {
TC1CurrentTime = TC1WarningTimeformat; }
else { TC1CurrentTime = TC1ReportTimeformat; }
在上面的示例中,TC1WarningTime 是 30/6/2013 04:00,TC1ReportTime 是 30/6/2013 03:00。所以 TC1WarningTime 应该 > TC1ReportTime,但是为什么结果给我的是 TC1ReportTimeformat 而不是 TC1WarningTimeformat?