温馨提示×

小程序date怎么在页面显示

小新
217
2020-12-08 11:12:20
栏目: 云计算

小程序date怎么在页面显示

小程序date在页面显示的案例:

.wxml代码:

<!--index.wxml-->

<view class="container">

  <!-- 建立按钮,为按钮绑定函数 -->

  <button bindtap="getTime">点击获取当前时间</button>

  <!-- wx:if判断是否存在 -->

  <text wx:if="{{time}}">{{time}}</text>

.js代码:

//index.js

var util = require('../../utils/util.js');

Page({

data: {

},

//给按钮绑定getTime事件

getTime:function(){

var time = util.formatTime(new Date())

//为页面中time赋值

this.setData({

time:time

})

//打印

console.log(time)

}

})


0