微信小程序获取星期显示到页面

wxml代码

1
<text>{{UTCDay}}</text>

js代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
onLoad: function () {
var UTCDay = new Date().getUTCDay()
switch (UTCDay) {
case 1:
this.setData({
UTCDay: "星期一"
})
break;
case 2:
this.setData({
UTCDay: "星期二"
})
break;
case 3:
this.setData({
UTCDay: "星期三"
})
break;
case 4:
this.setData({
UTCDay: "星期四"
})
break;
case 5:
this.setData({
UTCDay: "星期五"
})
break;
case 6:
this.setData({
UTCDay: "星期六"
})
break;
case 7:
this.setData({
UTCDay: "星期日"
})
break;
}
}

ps:获取其他时间方法一样

扫一扫,打赏我
Fanyun Fanyun
Copyright©1993 - Now. 瞎塔码搞