小程序中的日期格式化
1.创建wxs文件(util.wxs)
//timestamp 时间戳
//option 格式(年月日 就输入YY-MM-DD 时分 就输入 hh-mm)
//功能如下注释 ↓↓↓↓
formatDate(timestamp, option) {
var date = getDate(timestamp);
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
var hour = function () {
return date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
}
var minute = function () {
return date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
}
var second = function () {
return date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
}
//获取 年月日
if (option == 'YY-MM-DD') return " " + year + "-" + month + "-" + day;
//获取年月
if (o