====================================
程式碼如下:
//檢查時間有無符合後大於前- //日期格視為格式yyyy/MM/dd HH:mm function CheckTime() { string_1 = $('#StartDateTime').val(); string_2 = $('#EndDateTime').val(); DateTime1 = string_1.split(" "); //區分yyyy/MM/dd 與 HH:mm DateTime2 = string_2.split(" "); Date1 = DateTime1[0].split("/"); //區分yyyy ; MM ; dd Date2 = DateTime2[0].split("/"); Time1 = DateTime1[1].split(":"); //區分HH ; mm Time2 = DateTime2[1].split(":"); //區分HH ; mm var TrueDate1 = new Date(Date1[0], (parseInt(Date1[1]) - 1).toString(), Date1[2], Time1[0], Time1[1], 0, 0); var TrueDate2 = new Date(Date2[0], (parseInt(Date2[1]) - 1).toString(), Date2[2], Time2[0], Time2[1],0,0); if (TrueDate1 <= TrueDate2) { return true; } return false; }
當然一定有更好的寫法,趕時間就先這樣用了~
Reference:
http://www.w3schools.com/js/js_obj_date.asp
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date
沒有留言:
張貼留言