<uni-datetime-picker :start="Date.now()" type="daterange"></uni-datetime-picker>

- 发布:2025-08-18 14:14
- 更新:2025-08-19 10:48
- 阅读:185
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 4.76
第三方开发者工具版本号: 3.9.11
基础库版本号: 2.9.41
项目创建方式: HBuilderX
示例代码:
操作步骤:
无
无
预期结果:
不报错
不报错
实际结果:
报错
报错
bug描述:
uni-datetime-picker组件daterange下设置start时选择时间确认时会报错



爱豆豆 - 办法总比困难多
你好 刚测试了下 确实会出现这个问题
组件内部比较时间的代码中兼容ios端代码少了类型判断
可以在组件中修改dateCompare 和 diffDate 的代码
startDate = new Date(startDate.replace('-', '/').replace('-', '/'))
endDate = new Date(endDate.replace('-', '/').replace('-', '/'))
修改为以下代码
if (typeof startDate === 'string') {
startDate = new Date(startDate.replace('-', '/').replace('-', '/'))
}
if (typeof endDate === 'string') {
endDate = new Date(endDate.replace('-', '/').replace('-', '/'))
}
或者用字符串格式化后的时间字符串也是不会报错的<uni-datetime-picker start="2025-08-11" type="daterange" />
-
-
-
-
-
-
-
-
-
-
回复 1***@qq.com: 一样的啊 https://ext.dcloud.net.cn/plugin?id=3962 uni-ui中uni-datetime-picker也是这个
2025-08-19 09:25
-
-
-
回复 1***@qq.com: 复现了 npm安装的话最新包是1.5.1
但是官方插件市场的都已经更新到1.5.9了 https://ext.dcloud.net.cn/plugin?id=55&update_log
估计是老版本的bug2025-08-19 12:04
-
-
-
-
-
回复 1***@qq.com: 你是hx创建的项目,可以先自行修改下 function dateCompare(startDate, endDate) {
startDate = new Date(fixIosDateFormat(typeof startDate === 'string' ? startDate.trim() : startDate))
endDate = new Date(fixIosDateFormat(typeof endDate === 'string' ? endDate.trim() : endDate))
return startDate <= endDate
}2025-08-19 17:12
-
1***@qq.com (作者)
版本是1.5.10吗
2025-08-18 14:45