我在比较日期格式时遇到问题: 05/31/2017 10:50 AM(IST)和20170531 003837.000(EST)使用Date.parse。这有什么线索?。
//Capture input for debug
var Outlmd = "05/31/2017 10:50 AM";
var Outlsr = "20170531 003837.000";
//Convert to internal format - milliseconds since epoch
d1 = Date.parse(05/31/2017 10:50 AM);
d2 = Date.parse(20170531 003837.000);
if(d1 > d2) { NewTempDate = lmd; } else { NewTempDate = lsr; }
答案 0 :(得分:-1)
你忘记了Date.parse
中的引用执行Date.parse('05/31/2017 10:50 AM')
<强>更新强> 请考虑以下代码:
//Capture input for debug
var lmd = "05/31/2017 10:50 AM";
var lsr = "2017-05-31T00:45:25-0400";
//Convert to internal format - milliseconds since epoch
d1 = Date.parse(lmd);
d2 = Date.parse(lsr);
if(d1 > d2) { NewTempDate = lmd; } else { NewTempDate = lsr; }
请注意lmd和lsr应该是可解析的数据字符串,没有额外的空格:&#34; 2017-05-31T00:45:25-0400&#34;不是&#34; 2017-05-31T00:45:25-0400&#34;