webApp在ios中使用js将2017-11-15 12:13转为毫秒数失败

HTML5开发webAPP,需要将日期2017-11-15 12:13转为毫秒数

function (time){ 
   return new Date(time).getTime();
}

使用上述方法,在安卓机上正常,在ios中返回值为空


缥缈止盈
浏览 882回答 2
2回答

qq_花开花谢_0

上面的方法在安卓上没有问题,在ios上,当只有年月日的时候也没有问题,但是如果加上小时分钟,就会返回NAN上面的方法可以改为:function timeTolong(time){&nbsp; &nbsp; &nbsp; &nbsp; var arr = time.replace(" ", "-").replace(":", "-").replace(":","-").split("-");&nbsp; &nbsp; &nbsp; &nbsp; for(var i = 0; i < 6; i++){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!arr[i]){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arr[i] = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return new Date(arr[0],arr[1]-1,arr[2],arr[3],arr[4],arr[5]).getTime();&nbsp; &nbsp; }

三国纷争

function (time){&nbsp; &nbsp; var n = time.replace(new RegExp('-', 'gm'), '/')&nbsp; &nbsp; return new Date(n).getTime();}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

WebApp