目前,我使用:檢測,如果字符串可以轉換成日期
var d = new Date("March 7 2012");
document.write(d.getMonth() + 1);
如果日期字符串是一個很奇怪的像No Date
即:
var d = new Date("No Date"); // anything which isn't recognisable as a date
document.write(d.getMonth() + 1);
這裏的輸出我得到是NaN
如果發生類似情況,我該如何顯示更好的信息
可能重複(http://stackoverflow.com/questions/1353684/detecting-an-invalid-date-date-instance-in-javascript) – 2012-03-07 16:40:26