您描述的缺陷也出現在Safari,Firefox和Chrome中。而不是修復庫,這是一個簡單的函數來解析你的日期格式。 2位數字不是一個好主意,功能將它們視爲+2000。三位和四位數年份按原樣處理。
// Parse date format dd-mmm-yy hh:mm ap
// Two digit years are treated as 2000
// Years of three digits or more are treated as is
function parseDmY(s) {
var months = {jan:0,feb:1,mar:2,apr:3,may:4,jun:5,
jul:6,aug:7,sep:8,oct:9,nov:10,dec:11};
var b = s.split(/[- :]/);
var h = (b[3]%12) + (/pm/i.test(b[5])? 12 : 0);
var y = +b[2] + (b[2] < 100? 2000 : 0)
return new Date(y, months[b[1].toLowerCase()], b[0], h, b[4]);
}
console.log(parseDmY('10-Jun-2015 12:00 pm'));
兩位數的年份也可以在當前年份的-70到+30的範圍內進行處理。
適合我的作品,你確定這是你試過的嗎? – Arvind
而不是Date.parse爲什麼你不嘗試'new Date(start_time)' –
是不是應該用引號? – Incognito