微信小程序时钟(xx年xx月xx日xx:xx格式)

wxml:

<view>时间:{{newTime}}</view>

js:

page({
    data:{
        newTime:‘‘
    },
    onLoad: function (options) {
    var that = this;
    //获取实时时间
    setInterval(function () {
      var nowTime = new Date();
      var hour = nowTime.getHours();
      var minutes = nowTime.getMinutes();
      if (hour < 10) {
        hour = "0" + hour;
      }
      if (minutes < 10) {
        minutes = "0" + minutes;
      }
      //console.log("nowTime:",nowTime)
      that.setData({
        newTime: nowTime.getFullYear() + ‘年‘ + (nowTime.getMonth() + 1) + ‘月‘ + nowTime.getDate() + "日" + hour + ‘:‘ + minutes
      })
    }, 200)
  },
})    

  

微信小程序时钟(xx年xx月xx日xx:xx格式)

上一篇:微信公众号开发纪要(4)-调用微信扫一扫功能


下一篇:纯css手写圆角气泡对话框 微信小程序和web都适用