鸿蒙-日期格式化输出(ArkTS)

DevEco Studio 版本:DevEco Studio NEXT Developer Preview2(4.1.3.700)
HarmonyOS API 版本:4.1.0(11)

日期格式化输出(ArkTS)

1
2
3
4
5
6
7
8
9
10
11
// 时间戳转换为显示时间输出
function timestampToDate(t: number): string {
let date = new Date(t);
const year = date.getFullYear();
const month = ("0" + (date.getMonth() + 1)).slice(-2);
const day = ("0" + date.getDate()).slice(-2);
const hours = ("0" + date.getHours()).slice(-2);
const minutes = ("0" + date.getMinutes()).slice(-2);
const seconds = ("0" + date.getSeconds()).slice(-2);
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
作者

Dench

发布于

2024-07-09

更新于

2024-07-09

许可协议

CC BY-NC-SA 4.0

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×