Small program JS time comparison (compatible with IOS)

Problem Description

踩过的坑:iOS本地时间返回的格式和安卓系统的不一样

solution:

How compatible, please take a look at the code! Transparent. . .

const time1 = "2019-02-14 21:00:00";
const time2 = "2019-05-01 09:00:00";
const getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
      (dateFinal - dateInitial) / (1000 * 3600 * 24);
const _exceedTime = `${
    
    getDaysDiffBetweenDates(new Date(time1.replace(/-/g, '/')), new Date(time2.replace(/-/g, '/')))}`

Summarize:

So how to solve the compatibility problem:

For example: only need to add .replace(/-/g, '/'))to achieve compatibility.

Guess you like

Origin blog.csdn.net/qq_50851509/article/details/130389809