#鸿蒙学习大百科#如何展示一段完整的时间?

如何展示一段完整的时间?

HarmonyOS
2024-10-29 09:42:08
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
后知后觉cy
// 导入模块
import { intl } from '@kit.LocalizationKit';

@Entry
@Component
struct Index {
  @State time: string = ''
  build() {
    Column() {
      Text(this.time).fontSize(20)
        .margin(10)
      Button("点击").onClick(() => {
        // 设置要格式化的日期
        let date = new Date(2021, 8, 17, 13, 4, 0);
        // 在软件上展示完整的时间信息
        let dateFormat1 = new intl.DateTimeFormat('zh-CN', { dateStyle: 'full', timeStyle: 'full' });
        this.time = dateFormat1.format(date); // formattedDate1: 2021年9月17日星期五 中国标准时间 13:04:00
      })
    }
    .height("100%")
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.

分享
微博
QQ
微信
回复
2024-10-29 15:25:05


相关问题
#鸿蒙学习大百科#ArkTS如何生成xml?
885浏览 • 1回复 待解决
#鸿蒙学习大百科#如何实现ui优化?
652浏览 • 1回复 待解决