function formatTime(dateStr){
const date = new Date(dateStr)
const Month = date.getMonth() + 1
const Day = date.getDate()
const Y = date.getFullYear() + '-'
const M = Month < 10 ? '0' + Month + '-' : Month + '-'
const D = Day + 1 < 10 ? '0' + Day : Day
return Y + M + D
}
该博客介绍了JavaScript中一个用于格式化日期的function `formatTime`。此函数接受一个日期字符串作为输入,然后返回格式为`年-月-日`的日期。例如,将月份不足两位的数字前补零,确保日期始终为两位数。
744

被折叠的 条评论
为什么被折叠?



