微信小程序IOS系统兼容 Date.parse() 时间字符串转时间戳

IOS系统下,若时间为 2021-08-10 16:01:01 包含 “-” 字符,若使用 Date.parse() 进行转换,则会报 NAN 异常,在微信开发工具正常,在真机上异常;

需要将分隔符 "-" 转成 “/” 

/**
 * 将时间格式中的 '-' 转换成IOS 下可以识别的 '/'
 * @param {*} date_str  时间串
 */
function getDateTimeForIOS(date_str) {
  if (date_str.indexOf('-') === -1) {
    return (date_str + '').replace(/-/g, '/')
  } else {
    return date_str;
  }
}

exports.getDateTimeForIOS = getDateTimeForIOS;
原文地址:https://www.cnblogs.com/WQ1992/p/15125311.html