ios上獲取時間戳出錯
阿新 • • 發佈:2018-12-30
獲取當前時間:
function getCurTime() {
var now = new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;
var date=now.getDate();
var hour=(now.getHours()<10)?("0"+now.getHours()):now.getHours();
var minute=(now.getMinutes()<10)?("0"+now.getMinutes()):now.getMinutes();
var second=(now.getSeconds()<10)?("0"+now.getSeconds()):now.getSeconds();
var curTime=year+"-"+month+"-"+date +" "+hour+":"+minute+":"+second;
return (new Date(curTime)).getTime();
}
getCurTime();//得到的 curTime是 2017-08-23 16:09:00
然而這樣在iOS手機上卻會報錯,只有改成 2017/08/23 16:09:00 形式的才行。
so,大家注意嘍!為了解決這個問題 繞了好大彎,也是醉了
var now = new Date();var year=now.getFullYear();
var month=now.getMonth()+1;
var date=now.getDate();
var hour=(now.getHours()<10)?("0"+now.getHours()):now.getHours();
var minute=(now.getMinutes()<10)?("0"+now.getMinutes()):now.getMinutes();
var second=(now.getSeconds()<10)?("0"+now.getSeconds()):now.getSeconds();
var curTime=year+"/"+month+"/"+date +" "+hour+":"+minute+":"+second;
return (new Date(curTime)).getTime();