我尝试制作一个小部件,它基本上显示时间,但我不知道如何更新时间。
这是我的小部件代码:
var date = new Date();
var t1 = date.getHours();
var t2 = date.getMinutes();
var t3 = date.getSeconds();
var t = t1 + ":" + t2 + ":" + t3;
function widget(t) {
let widget = new ListWidget()
let text = widget.addText("Time:")
text.font = Font.semiboldSystemFont(20);
text.centerAlignText()
let time = widget.addText(t.toString(10));
time.font = Font.semiboldSystemFont(20);
time.centerAlignText()
let startColor = new Color("#3050cc")
let endColor = new Color("#050530")
let gradient = new LinearGradient()
gradient.colors = [startColor, endColor]
gradient.locations = [0.0, 1]
widget.backgroundGradient = gradient
widget.backgroundColor = new Color("#ff5401")
return widget
}
let myWidget = widget(t)
Script.setWidget(myWidget)
Script.complete()
感谢您的每一次帮助!