时间封装调用
先导入组件: ohpm i dayjs
import dayJs from 'dayjs'
@Entry
@Component
struct ChiJiuHuaPage {
@State time: number = 1716168928000
@State nowTime: number = Date.now()
build() {
Column() {
Text(`${dayJs(this.nowTime).format('MM/DD hh:mm')}`)
.fontSize(24)
.margin({ top: 46 })
Text(`${dayJs(this.nowTime).format('YYYY/MM/DD')}`)
.fontSize(24)
.margin({ top: 46 })
Text(`${dayJs(this.nowTime).format('YYYY-MM-DD')}`)
.fontSize(24)
.margin({ top: 46 })
Text(`${dayJs(this.nowTime).format('YYYY-MM-DD hh:mm:ss')}`)
.fontSize(24)
.margin({ top: 46 })
Text(`${dayJs(this.nowTime).format('YYYY-MM-DD hh:mm:ss')}`)
.fontSize(24)
.margin({ top: 46 })
}
.backgroundImageSize({ height: '100%', width: '100%' })
.height('100%')
.width('100%')
}
}