- 关于 timeStamp 语法,参考 https://developers.weixin.qq.com/miniprogram/dev/api/open-api/payment/wx.requestPayment.html
小程序时间戳转换为日期
1.导出

const formatTime = date
= { var date
= new Date() const year
= date
.getFullYear() const month
= date
.getMonth() + 1 const day
= date
.getDate() const hour
= date
.getHours() const minute
= date
.getMinutes() const second
= date
.getSeconds() return [year
, month
, day
].map(formatNumber
).join('/') + ' ' + [hour
, minute
, second
].map(formatNumber
).join(':')}const formatNumber = n
= { n
= n
.toString() return n
[1] ? n
: '0' + n
}module
.exports
= { formatTime
: formatTime
,}2.导入
const time
= require("../../utils/util.js");3.使用
var currenttime
= res
.data
.timeStamp
;console
.log(time
.formatTime(currenttime
, 'Y/M/D h:m:s'));
4.注意了喔 date.getFullYear is not a function 是因为util.js中没有写下面一行代码

小程序
TAG标签:
微信小程序js字符串转日期
http://www.xiaochengxub.com/read-100791.html