HarmonyOS应用开发-显示时间的实现

鸿蒙时代
发布于 2022-4-23 10:19
浏览
1收藏

HarmonyOS应用开发-显示时间的实现-鸿蒙开发者社区
一.创建项目
HarmonyOS应用开发-显示时间的实现-鸿蒙开发者社区
二.示例代码
hml:

<div class="container">
    <text class="title">现在的时间是:</text>
    <text class="title">{{ year }}年{{ mouth }}月{{ day }}日</text>
    <text class="title">{{ hour }}:{{min}}</text>
</div>

css:

.container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.title {
    font-size: 30px;
    margin: 10px;
}

js:

export default {
    data: {
        year:"",
        mouth:"",
        day:"",
        hour:"",
        min:"",
    },
    onShow(){
        this.getDate();
    },
    getDate:function(){
        let newDate = new Date();
        this.year = newDate.getFullYear();
        this.mouth = newDate.getMonth();
        this.day = newDate.getDay();
        this.hour = newDate.getHours();
        this.min = newDate.getMinutes();
    }
}

分类
标签
HarmonyOS应用开发-显示时间的实现.docx 40.12K 36次下载
2
收藏 1
回复
举报
回复
    相关推荐