HarmonyOS Next中如何在arkts中格式化时间戳?-灵析社区

应该是最帅的鹅

HarmonyOS Next中如何在arkts中格式化时间戳? 比如将1611081385000格式化为:2021-01-20 02:36:25

阅读量:141

点赞量:0

问AI
口味你好,你可以通过以下示例代码转换: let date = new Date(1710161336 * 1000); 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); let formattedDate = "${year}-${month}-${day} ${hours}:${minutes}:${seconds}"