TypeScript中,时间戳转年月日形式显示
2022-10-25 本文已影响0人
全新的饭
// 时间戳(精确到秒,10位)转为'xx年xx月xx日'
public timestampToDate(timestamp: number): string
{
const date = new Date(timestamp*1000);
const year = date.getFullYear();
const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
const day = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate();
const str = `${year}年${month}月${day}日`;
return str;
}