HarmonyOS ArkTS调用JS库

HarmonyOS中没有转时间格式的三方库,现在想使用moment.js如何在项目导入和使用?

HarmonyOS
2024-12-25 09:24:38
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

可以使用三方库dayjs,下载安装:

ohpm install dayjs 

使用:

import dayjs from "dayjs";

示例参考:

import dayjs from "dayjs";

@Entry
@Component
struct Index {
  @State timeStr: number = 1714991876;
  @State timeNow: string = ''

  build() {
    Row() {
      Column() {
        Text('当前时间:' + this.timeNow).fontSize(20).fontWeight(FontWeight.Bold).width("100%")
        Button("get time").onClick(() => {
          try {
            this.timeNow = dayjs.unix(this.timeStr).format('YYYY-MM-DD HH:mm:ss')
          } catch (e) {
          }
        })
      }.justifyContent(FlexAlign.Center).width('100%')
    }.height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-25 11:42:29
相关问题
HarmonyOS ArkTS如何引入和调用JS
2367浏览 • 1回复 待解决
HarmonyOS ArkTS如何调用web前端的js
871浏览 • 1回复 待解决
HarmonyOS ArkTS调用so
2567浏览 • 1回复 待解决
HarmonyOS 怎么调用nodejs的 js
864浏览 • 1回复 待解决
ArkTS项目如何调用已有SO?
2029浏览 • 1回复 待解决
ArkTS调用js/ts代码会有性能损耗吗
4533浏览 • 2回复 待解决
HarmonyOS 如何调用js代码?
956浏览 • 1回复 待解决
ArkTS不支持使用第三方的js
5725浏览 • 1回复 待解决
HarmonyOS native层js代码调用
1012浏览 • 1回复 待解决
js调用Java,问题求助?
6628浏览 • 1回复 待解决
HarmonyOS 调用C
1075浏览 • 1回复 待解决
HarmonyOS js调用webview中的方法
1580浏览 • 1回复 待解决
JS调用PA出现RemoteInterfaceProxy异常
8048浏览 • 2回复 待解决
HarmonyOS ohosTest调用so失败
1108浏览 • 1回复 待解决
openHarmony js如何调用http/https接口
5443浏览 • 0回复 待解决
如何支持HarmonyOS调用JS方法及传参?
1626浏览 • 1回复 待解决
HarmonyOS 如何调用工程里的js文件
1152浏览 • 1回复 待解决
引用js静态检查报错
1649浏览 • 1回复 待解决
HarmonyOS ArkTS如何调用.so包
966浏览 • 1回复 待解决