


What this article brings to you is about the WeChat applet example: the acquisition code that implements system time, timestamp time, and timestamp addition and subtraction. It has certain reference value. Friends in need can refer to it. I hope It will help you.
//获取当前时间戳 var timestamp = Date.parse(new Date()); timestamp = timestamp / 1000; console.log("当前时间戳为:" + timestamp); //获取当前时间 var n = timestamp * 1000; var date = new Date(n); //年 var Y = date.getFullYear(); //月 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1); //日 var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); //时 var h = date.getHours(); //分 var m = date.getMinutes(); //秒 var s = date.getSeconds(); console.log("当前时间:" +Y+M+D+h+":"+m+":"+s); //转换为时间格式字符串 console.log(date.toDateString()); console.log(date.toGMTString()); console.log(date.toISOString()); console.log(date.toJSON()); console.log(date.toLocaleDateString()); console.log(date.toLocaleString()); console.log(date.toLocaleTimeString()); console.log(date.toString()); console.log(date.toTimeString()); console.log(date.toUTCString());
//时间、时间戳加减 以加一天举例,聪明的你肯定触类旁通 //加一天的时间戳: var tomorrow_timetamp = timestamp + 24 * 60 * 60; //加一天的时间: var n_to = tomorrow_timetamp * 1000; var tomorrow_date = new Date(n_to); //加一天后的年份 var Y_tomorrow = tomorrow_date.getFullYear(); //加一天后的月份 var M_tomorrow = (tomorrow_date.getMonth() + 1 < 10 ? '0' + (tomorrow_date.getMonth() + 1) : tomorrow_date.getMonth() + 1); //加一天后的日期 var D_tomorrow = tomorrow_date.getDate() < 10 ? '0' + tomorrow_date.getDate() : tomorrow_date.getDate(); //加一天后的时刻 var h_tomorrow = tomorrow_date.getHours(); //加一天后的分钟 var m_tomorrow = tomorrow_date.getMinutes(); //加一天后的秒数 var s_tomorrow = tomorrow_date.getSeconds();
Related recommendations:
WeChat Mini Program Example: Judgment Code for Sharing to One Person or to a Group
The above is the detailed content of WeChat applet example: code for obtaining system time, timestamp time, and timestamp addition and subtraction. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor
