发现了一个很好的网站
本笔记的内容也主要来源于该网站
一、获取时间
示例:
.js:
Page({
data: {
},
onLoad: function (options) {
var date = new Date
// getTime()
console.log("getTime() ", date.getTime(), " ", typeof(date.getTime()))
// getFullYear()
console.log("getFullYear() ", date.getFullYear(), " ", typeof(date.getFullYear()))
// getMonth()
console.log("getMonth() ", date.getMonth(), " ", typeof(date.getMonth()))
// getDate()
console.log("getDate() ", date.getDate(), " ", typeof(date.getDate()))
// getHours()
console.log("getHours() ", date.getHours(), " ", typeof(date.getHours()))
// getMinutes()
console.log("getMinutes() ", date.getMinutes(), " ", typeof(date.getMinutes()))
// getSeconds()
console.log("getSeconds() ", date.getSeconds(), " ", typeof(date.getSeconds()))
// getMilliseconds()
console.log("getMilliseconds() ", date.getMilliseconds(), " ", typeof(date.getMilliseconds()))
// getDay()
console.log("getDay() ", date.getDay(), " ", typeof(date.getDay()))
},
})
运行结果:
二、设置时间
示例:
.js:
Page({
data: {
},
onLoad: function (options) {
var date = new Date
date.setTime(1597222026977)
// getTime()
console.log("getTime() ", date.getTime(), " ", typeof(date.getTime()))
// getFullYear()
console.log("getFullYear() ", date.getFullYear(), " ", typeof(date.getFullYear()))
// getMonth()
console.log("getMonth() ", date.getMonth(), " ", typeof(date.getMonth()))
// getDate()
console.log("getDate() ", date.getDate(), " ", typeof(date.getDate()))
// getHours()
console.log("getHours() ", date.getHours(), " ", typeof(date.getHours()))
// getMinutes()
console.log("getMinutes() ", date.getMinutes(), " ", typeof(date.getMinutes()))
// getSeconds()
console.log("getSeconds() ", date.getSeconds(), " ", typeof(date.getSeconds()))
// getMilliseconds()
console.log("getMilliseconds() ", date.getMilliseconds(), " ", typeof(date.getMilliseconds()))
// getDay()
console.log("getDay() ", date.getDay(), " ", typeof(date.getDay()))
},
})
运行结果: