Home >WeChat Applet >Mini Program Development >What should I do if the new Date() method of the applet fails?

What should I do if the new Date() method of the applet fails?

hzc
hzcforward
2020-06-29 10:54:522859browse

The iOS system has format requirements for the new Date() method in js

let dt = new Date("2019-07-24 19:57")
// dt会返回valid Date

The correct way to write it should be

let dt = new Date("2019/07/24 19:57")

In fact, most of the date formats in the process are 2019-07- 24, so in the actual application process, it is necessary to use regular expressions to preprocess the string

let tm = "2019-07-24 19:57"
let dt = new Date(tm.replace(/-/g,'/'))

During the development of the small program, a date conversion method was used, but it didn’t work on Apple’s mobile phone. I searched online. I just discovered this problem and recorded the

recommended tutorial: "WeChat Mini Program"

The above is the detailed content of What should I do if the new Date() method of the applet fails?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jianshu.com. If there is any infringement, please contact admin@php.cn delete