yyyy-MM-dd hh:mm:ss 转换为时间戳

在处理服务端返回的时间数据方面,对返回的日期时间非时间戳的情况下。需要转换成时间戳进行判断,或者比较。

// 当前时间
new Date().getTime()
// 2021-05-20 18:00:00  服务端返回时间参数值
const timer = '2021-05-20 18:00:00'

// 1621504800000
Date.parse(timer.replace(/-/g, '/'))

注意:new Date() 直接处理 timer 在Ios,safari,会存在兼容问题~

兼容问题
IOS机型

你可能感兴趣的:(yyyy-MM-dd hh:mm:ss 转换为时间戳)