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()
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()
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!