JavaScript 有许多处理日期的方法,toLocaleDateString()
可以将日期的标準格式,转换为仅保留日期(不含时间)的字串格式。
toLocaleDateString() returns the date (not the time) of a date, as a string, using locale conventions:
实际操作
串接 API 时取得的资料格式,是一组标準的日期格式。
activity: { StartTime: '2022-01-09T01:34:29+08:00';}
原本写法:取得 YYYY-MM-DD 并将 '-' 转换成 '/'
activity.StartTime.substr(0,10).split('-').join('/')
更好的写法:建立物件,仅保留日期并转换为字串
new Date(activity.StartTime).toLocaleDateString()