申請博客好幾個月了,一直想寫一些東西可是總覺着本身寫很差,就一直擱淺了。廢話很少說,進入正題!html
ios中和Safari瀏覽器中對js Date對象的支持前端
1.問題情形是這樣的,須要在特定的時間顯示不一樣的內容。ios
解決辦法有兩種:chrome
1.經過後臺獲取服務器的時間。瀏覽器
在返回給前端標誌,前端經過模板也好,經過其餘方式進行判斷也好,顯示不一樣的內容。這個咱們無論...服務器
2.經過本地獲取系統時間顯示不一樣的內容。函數
我採用的就是這種方式,可是這裏就出現了問題。附上代碼測試
function setContentWithTime(time){ var current = new Date(), setDate = new Date(time).getTime(); var curTime = new Date(current.getFullYear()+'-'+(current.getMonth()+1)+'-'+current.getDate()).getTime(); if(curTime == setDate){ ... }else{ ... } }
setContentWithTime("2015-8-13");
上面這段代碼在chrome和ff裏面跑都沒有問題。可是在safari裏面跑就出現了問題。spa
問題以下:.net
ok,問題就出現了,在safari裏面是沒法對形如"xxxx-xx-xx"這種形式的日期進行變換,在safari裏面
4.在那些ios系統中是不支持js 的Date()這種轉換的。請你們測試一下,本人知道的是在ios8.4裏面仍然存在這個問題。
5.提到這裏咱們也能夠再次查看js Date對象裏面的構造方法會發現。其實咱們能夠採起另外的方法進行new Date;
查資料發現Date的構造函數:new Date()new Date(milliseconds)new Date(datestring)new Date(year, month)new Date(year, month,day)new Date(year, month, day, hours)new Date(year, month, day, hours, minutes)new Date(year,month, day, hours, minutes, seconds)new Date(year, month, day, hours, minutes, seconds,microseconds)
這裏須要注意的是:
結語:實際上是個小問題,可是在作項目的過程當中,老是讓人頭疼,請你們勿噴!!!謝謝!
參考文獻:
http://www.w3school.com.cn/jsref/jsref_obj_date.asp
http://blog.sina.com.cn/s/blog_6a0cd5e501011so7.html
http://www.cnblogs.com/keke/p/3372558.html
http://blog.csdn.net/liu510817387/article/details/8688216