uni-app取日期用到,代码如下
new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * i)
chrome浏览器返回:YYYY/MM/DD
真机返回:周 月 日 年
解决办法:
function getYearMonthDay(date) {
return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate()
}
本文介绍了一种在uni-app中解决不同环境下日期显示不一致的问题。通过自定义函数getYearMonthDay来统一日期格式,确保在Chrome浏览器和真机上都能正确显示为YYYY/MM/DD的格式。
uni-app取日期用到,代码如下
new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * i)
chrome浏览器返回:YYYY/MM/DD
真机返回:周 月 日 年
解决办法:
function getYearMonthDay(date) {
return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate()
}
1354
1272
1700

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