我有数据,其中包含日期。它以 Unix 时间戳格式保存。我正在寻找一种方法,如何在 JSpreadSheet (“jspreadsheet-ce”)中显示此数据,使其看起来像日期(例如 YYYY/MM/DD)。现在只是 13 位数字,看起来很糟糕。
我尝试将列类型设置为“日期”(没有更改)和“日历”(数据未显示)。我也尝试设置 dateFormat,但没有任何改变。
// Assuming your Unix Timestamps are stored in the `timestamp` column
const data = [
{ timestamp: 1629889200 },
{ timestamp: 1630158600 },
];
data.forEach(item => {
item.formattedDate = new Date(item.timestamp * 1000).toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit'
});
});
//Display in JSpreadSheet:
jspreadsheet(document.getElementById('spreadsheet'), {
data: data,
columns: [
// ... other columns
{
title: 'Formatted Date',
data: 'formattedDate'
}
]
});