给定一个时间字符串 var time="2017-02-27 16:42:53
" js有三种转换为时间戳的方法:
1、var timestamp = Date.parse(time)
2、var timestamp = time.getTime()
3、var timestamp = time.valueOf()
第一种方法只能精确到秒,后两种能精确到毫秒。
然而相同的代码,在android上能正常执行,在ios上就会出错。
var time ='2017-02-27 16:42:53'; var date = time.substr(0, 10) var hour = time.substr(11, 2) == '00' ? 0 : time.substr(11, 2).replace(/(0+)/gi, "") var minute = time.substr(14, 2) == '00' ? 0 : time.substr(14, 2).replace(/(0+)/gi, "") var second = time.substr(17, 2) == '00' ? 0 : time.substr(17, 2).replace(/(0+)/gi, "") var timestamp = parseInt(new Date(date).getTime()) + parseInt(hour) * 3600 + parseInt(minute) * 60 + parseInt(second)