微信小程序時鍾(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)
  },
})    

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM