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
549浏览 • 1回复 待解决
HarmonyOS ArkTS如何调用web前端的js
265浏览 • 1回复 待解决
HarmonyOS ArkTS调用so
471浏览 • 1回复 待解决
HarmonyOS 怎么调用nodejs的 js
209浏览 • 1回复 待解决
ArkTS项目如何调用已有SO?
1262浏览 • 1回复 待解决
ArkTS调用js/ts代码会有性能损耗吗
3193浏览 • 2回复 待解决
HarmonyOS 如何调用js代码?
346浏览 • 1回复 待解决
HarmonyOS native层js代码调用
358浏览 • 1回复 待解决
ArkTS不支持使用第三方的js
4599浏览 • 1回复 待解决
HarmonyOS 调用C
361浏览 • 1回复 待解决
js调用Java,问题求助?
5769浏览 • 1回复 待解决
HarmonyOS js调用webview中的方法
727浏览 • 1回复 待解决
JS调用PA出现RemoteInterfaceProxy异常
7248浏览 • 2回复 待解决
HarmonyOS ArkTS如何调用.so包
138浏览 • 1回复 待解决
HarmonyOS ArkTS调用"ping"命令
215浏览 • 1回复 待解决
HarmonyOS ohosTest调用so失败
293浏览 • 1回复 待解决
HarmonyOS 如何调用工程里的js文件
150浏览 • 1回复 待解决
openHarmony js如何调用http/https接口
4596浏览 • 0回复 待解决