微信小程序> 小程序时间戳转换为日期

小程序时间戳转换为日期

浏览量:2124 时间: 来源:前端娱乐圈
  • 关于 timeStamp 语法,参考 https://developers.weixin.qq.com/miniprogram/dev/api/open-api/payment/wx.requestPayment.html

小程序时间戳转换为日期

1.导出

小程序

const formatTime = date = {  var date = new Date()//一定要记得写这个,不然会报date.getFullYear is not a function  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中没有写下面一行代码

小程序

小程序

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎