当前位置:网站首页>【Harmony OS】【ARK UI】Date 基本操作
【Harmony OS】【ARK UI】Date 基本操作
2022-08-09 04:44:00 【华为开发者论坛】
关于时间操作是很基础的操作,今天描述一个怎么获取时间戳,和获取当前时区,获取当期日期功能。主要分为:“开发准备“,“api讲解”,”运行效果“
1、开发准备
我们需要学会的资料如下
1.1【HarmonyOS】鸿蒙ets项目如何npm方式引入第三方js类库
1.2 Jstz
1.3对比参考JavaScript Date 对象
2、api讲解
2.1获取当前时区 参考Jstz仓库

2.2获取当前时间戳
var str= "2018-07-26";console.log(Date.parse(str)/1000+"")2.3获取当前时间 我们参数参考JavaScript Date 对象资料

3. 运行效果
3.1全部代码如下
import jstz from 'jstz';@[email protected] DataTimePage { private DateParse(){ var str= "2018-07-26"; console.log(Date.parse(str)/1000+"") } private gettime(){ let time=new Date(); console.log(time.getFullYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"日") } build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Text('获取当前时区') .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(function(){ var timezone = jstz.determine(); var Asia = timezone.name(); console.log( Asia); }) Text('日期转化为时间戳') .fontSize(50) .fontWeight(FontWeight.Bold) .backgroundColor(Color.Red) .onClick(this.DateParse.bind(this)) Text('获取当前日志') .fontSize(50) .fontWeight(FontWeight.Bold) .backgroundColor(Color.White) .onClick(this.gettime.bind(this)) } .width('100%') .height('100%') }}3.2运行效果如下

欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh
边栏推荐
- 【暑期每日一题】洛谷 P1216 [USACO1.5][IOI1994]数字三角形 Number Triangles
- 如何剪裁svg并压缩
- P1163 银行贷款
- 换座位[异或巧妙的让奇偶互换]
- Talking about the process and how to create it
- LeetCode - remove consecutive nodes with a sum of zero from a linked list
- 钉钉与RStudio快捷方式冲突--钉钉快捷键设置
- The influence law of genes for disease - read the paper
- AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline'
- etcd Study Notes - Getting Started
猜你喜欢
随机推荐
Example of 360 assessment feedback questions
软件质效领航者 | 优秀案例•东风集团DevOps改革项目
抖音直播间带货最新玩法和运营技巧
容易混淆的指针知识点
TCP/IP协议中分包与重组原理介绍、分片偏移量的计算方法、IPv4报文格式
器件可靠性与温度的关系
【暑期每日一题】洛谷 P5729 【深基5.例7】工艺品制作
JS-全局dom对象的使用---使用htm样式和js函数动作的完全分离
换座位[异或巧妙的让奇偶互换]
杰理之采用mix out eq 没有作用【篇】
A case of missing heritability
稳定性测试怎么做,这篇文章彻底讲透了!
浙江DAMA-CDGA/CDGP数据治理认证招生简章
I.MX6U-ALPHA开发板(串口实验)
如何剪裁svg并压缩
整除性质1
LN论文、五种归一化原理和实现
Ali YunTianChi competition problem (machine learning) - ali cloud security malware detection (complete code)
ceph创建存储池,映射,删除练习
OKR管理过程中,如何运用CFR实现组织的高效对话、反馈和认可?









