把固定格式日期转化为时间戳:
复制代码
1
2
3
4
5
6
7
//格式化当地日期
new Date('2017-11-11 0:0:0')
//结果为:Sat Nov 11 2017 00:00:00 GMT+0800 (中国标准时间)
//日期转化为当地时间戳
Date.parse(new Date('2017-11-11 0:0:0'))
//结果为:1510329600000
//当时在低版本ios系统下不能解析转化
兼容写法:
复制代码
1
2
3
4
5
6
7
8
9
//ios下写法:
Date.parse(new Date('2017/11/11 0:0:0'))
//兼容写法
Date.parse(new Date('2017-11-11 0:0:0'))||Date.parse(new Date('2017/11/11 0:0:0'))
//封装函数(data格式为2017-11-11)
function formatTimeStamp(date,time='0:0:0'){
return Date.parse(new Date(`${data} ${time}`))||Date.parse(new Date(`${data.replace(/-/g,'/')} ${time}`))
}
formatTimeStamp('2017-11-11');//已经兼容
最后
以上就是妩媚牛排最近收集整理的关于js---Date.parse()转化日期为时间戳,ios与Android兼容写法的全部内容,更多相关js---Date内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复