Home > WeChat Applet > Mini Program Development > What should I do if the date obtained by the mini program is incorrect?

What should I do if the date obtained by the mini program is incorrect?

angryTom
Release: 2020-03-25 13:47:29
Original
3804 people have browsed it

What should I do if the date obtained by the mini program is incorrect?

What should I do if the date obtained by the applet is incorrect?

Problem: When obtaining the current date, the date result is incorrect.

var userDate = new Date().toLocaleDateString()
Copy after login

Cause: In the WeChat applet, due to differences in regional versions of mobile phones, different formats may occur, resulting in some date calculation errors.

The solution is as follows:

var date= new Date();
var myDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
Copy after login

Use the splicing method directly to replace the original format to prevent the difference in time format obtained by the mobile phone regional version.

PHP Chinese website, a large number of free small program development tutorials, welcome to learn!

The above is the detailed content of What should I do if the date obtained by the mini program is incorrect?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template