Home  >  Article  >  WeChat Applet  >  How to get the current date in the applet

How to get the current date in the applet

王林
王林forward
2021-01-15 10:04:494710browse

How to get the current date in the applet

Implementation code:

(Learning video sharing: Programming video)

var timestamp = Date.parse(new Date());
var date = new Date(timestamp);
//获取年份  
var Y =date.getFullYear();
//获取月份  
var M = (date.getMonth() + 1 < 10 ? &#39;0&#39; + (date.getMonth() + 1) : date.getMonth() + 1);
//获取当日日期 
var D = date.getDate() < 10 ? &#39;0&#39; + date.getDate() : date.getDate(); 
console.log("当前时间:" + Y + &#39;年&#39;  + M+ &#39;月&#39; + D+ &#39;日&#39; );

console.log("Current time: " Y 'Year' M 'Month' D 'Day' );

The print results are as follows:

How to get the current date in the applet

Related recommendations:Small Program Development Tutorial

The above is the detailed content of How to get the current date in the applet. For more information, please follow other related articles on the PHP Chinese website!

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