Re: [問題] 請問date物件在瀏覽器上有限制嗎?

看板Ajax作者 (^^)時間15年前 (2010/01/28 10:13), 編輯推噓4(404)
留言8則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《dedek (我要快樂起來)》之銘言: : 各位前輩下面一段程式 : endtime這個變數丟給new Date後,在IE6上面執行沒問題, : 但是到了kkman或是IE7後,丟進去的資料到了 endtimedate就會是空值 : 想了好久 還是找不到原因,所以上來問問前輩 : 請問這要怎麼處理比較好? : 這段程式最主要是判斷textbox4的日期 不能比textbox3早 : var endtime = document.getElementById("TextBox4").value; : var starttime = document.getElementById("TextBox3").value; 果然是因為字串格式的問題 , fx 是不吃 yyyy-mm-dd 的 , 手動自己做個 replace - , / 的行為換成 yyyy/mm/dd 吧。 endtime=endtime.replace(/-/gi,"/"); starttime=starttime.replace(/-/gi,"/"); 換完之後如果還有問題再丟新的error format上來. : var endtimedate = new Date(endtime); : var starttimedat=new Date(starttime); : var compare = Date.parse(endtimedate.toString()) - Date.parse(starttimedat.toS : tring()) - Date.parse(starttimedat.toString()); : var comday = compare / (1000 * 60 * 24*60); -- I am a person, and I am always thinking . Thinking in love , Thinking in life , Thinking in why , Thinking in worth. I can't believe any of what , I am just thinking then thinking , but worst of all , most of mine is thinking not actioning... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 74.207.224.18

01/28 11:41, , 1F
謝謝T大幫忙!想問 同一隻程式不同瀏覽器,日期格式會不一樣?
01/28 11:41, 1F

01/28 11:51, , 2F
我是用月曆function 選擇日期,到textbox
01/28 11:51, 2F

01/28 11:52, , 3F
不同瀏覽器選擇出來的格式會不一樣!
01/28 11:52, 3F

01/28 11:52, , 4F
感謝T大幫忙謝謝謝謝
01/28 11:52, 4F

01/28 15:53, , 5F
如果允許的話,輸入GMT格式保證不會有問題
01/28 15:53, 5F

01/28 15:53, , 6F
Wed Dec 2 2009 19:13:49 GMT+0800
01/28 15:53, 6F

01/28 15:54, , 7F
這樣一定任何瀏覽器都吃~~~
01/28 15:54, 7F

01/29 22:08, , 8F
感謝感謝
01/29 22:08, 8F
文章代碼(AID): #1BOFBDfI (Ajax)
文章代碼(AID): #1BOFBDfI (Ajax)