学习笔记——微信小程序读取当前时间

html 复制代码
 <view class="box">
       <text>日期:</text>
       <view class="date">{{obtaindate}}</view>
 </view>

wxml中定义了一个文本元素,通过{{obtaindate}}获取js页面传递的日期数据

javascript 复制代码
data:{
    obtaindate:""
},
onload:function(){
    let date= new Date;
    let year = date.getfullYear();
    let mounth = date.getmounth();
    let day = date.getday();
    let obtaindate = "$year-$mounth-$day";
    this.setDate({
        obtaindate:obtaindate
});
},

js页面中定义了一个date,通过该对象获取年月日,并将其拼接起来,通过this.setDate方法将拼接好的日期写入页面中

运行结果如下

相关推荐
电子云与长程纠缠5 小时前
Godot学习05 - 播放与分离FBX动画
学习·游戏引擎·godot
蒸蒸yyyyzwd5 小时前
day3学习笔记
笔记·学习
red_redemption6 小时前
自由学习记录(143)
学习
楼田莉子7 小时前
MySQL数据库:MySQL的数据类型
数据库·学习·mysql
小陈phd7 小时前
系统架构师学习笔记(三)——计算机体系结构之存储系统
笔记·学习·系统架构
Rsun045518 小时前
AI智能体学习路线
人工智能·学习
feasibility.9 小时前
SSH Agent Forwarding 与 tmux 排障笔记
linux·运维·服务器·经验分享·笔记·ssh
charlie1145141919 小时前
通用GUI编程技术——Win32 原生编程实战(十六)——Visual Studio 资源编辑器使用指南
开发语言·c++·ide·学习·gui·visual studio·win32
知识分享小能手9 小时前
MongoDB入门学习教程,从入门到精通,MongoDB查询(4)
数据库·学习·mongodb
weixin_409383129 小时前
godot等轴视角tilemaplayer的学习 isocheric的素材xy大小怎么调
学习·游戏引擎·godot