export function formatDate(cellValue) {
if (cellValue == null || cellValue == "") return "";
var date = new Date(cellValue)
var year = date.getFullYear()
var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
}
这段代码定义了一个名为`formatDate`的函数,用于将日期时间值格式化为字符串。它接受一个`cellValue`参数,表示要格式化的日期时间值。
如果`cellValue`参数为`null`或空字符串,则函数返回空字符串。否则,函数使用`new Date(cellValue)`来创建一个`Date`对象,然后使用该对象的方法来获取年、月、日、时、分和秒等信息。
函数使用三元运算符来判断月、日、时、分和秒是否小于10,如果是,则在前面补充一个0。最后,函数将这些信息拼接成一个字符串,并返回。
这个函数的作用是将日期时间值格式化为`yyyy-MM-dd HH:mm:ss`的格式。