uni-app Dateformat 日期格式化问题 - DCloud 原数据2021-2-18T16:00:00.000Z显示成了NaN秒后
uni-app Dateformat 日期格式化问题 - DCloud 原数据2021-2-18T16:00:00.000Z显示成了NaN秒后
代码:<uni-dateformat :date="post.date1" :threshold="[0,0]"></uni-dateformat>
原数据:2021-2-18T16:00:00.000Z显示成了:NaN秒后
3 回复
bug已确认,感谢反馈。另外这种格式的日期是不正确的,如果你想用ISO标准日期字符串应该是YYYY-MM-DDTHH:mm:ss.sssZ这种格式的。月份应该是两位
更多关于uni-app Dateformat 日期格式化问题 - DCloud 原数据2021-2-18T16:00:00.000Z显示成了NaN秒后的实战教程也可以访问 https://www.itying.com/category-93-b0.html
写漏了,是ISO标准日期
这是因为uni-dateformat组件对ISO 8601格式的日期字符串解析存在问题。建议改用以下解决方案:
- 使用JavaScript Date对象代替原始字符串:
<uni-dateformat :date="new Date(post.date1)" :threshold="[0,0]"></uni-dateformat>
- 或者先处理日期格式:
// 在data或methods中
formatDate(dateStr) {
return new Date(dateStr);
}
- 在模板中使用:
<uni-dateformat :date="formatDate(post.date1)" :threshold="[0,0]"></uni-dateformat>