微信小程序显示当前时间


var timestamp =
 Date.parse(new Date());
//返回当前时间毫秒数
timestamp = timestamp / 1000;


//获取当前时间

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();


//  放在page外------------------------------------------------------------------------------------------------------------

//在onload里调用
 onLoad: function () {
    this.setData({
      logs: Y + "-" + M + "-" + D,
    })
  },

//logs 即为当前时间
 

猜你喜欢

转载自blog.csdn.net/qq_41261758/article/details/80754946