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

HarmonyOS应用开发-显示时间的实现_第1张图片

  • 创建项目

HarmonyOS应用开发-显示时间的实现_第2张图片 

 

  • 示例代码

hml:

现在的时间是: {{ year }}年{{ mouth }}月{{ day }}日 {{ hour }}:{{min}}

 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)