网站模版如何建,各大网站平台发布信息,免费下载访问迅雷网盘,专门做ppt背景的网站有哪些在开发微信小程序时#xff0c;使用了 uView 的 CountDown倒计时 组件和 uni.$u.timeFrom Api#xff0c;后台传递了一个时间字符串#xff0c;前台计算时间戳的差值#xff0c;来显示还有多久开始#xff0c;这个功能在模拟器和我自己手机#xff08;iphon13#xff09…在开发微信小程序时使用了 uView 的 CountDown倒计时 组件和 uni.$u.timeFrom Api后台传递了一个时间字符串前台计算时间戳的差值来显示还有多久开始这个功能在模拟器和我自己手机iphon13上都是正常的在提交测试之后测试反馈iphone12日期显示异常先后经历了三个版本的代码最终解决了此问题。
1 遇到的异常情况
还有 0天 0小时 开始NaN年前
2 结论和解决方案 IOS 系统的部分版本不支持 yyyy-mm-dd 格式需要将 - 替换为 /即修改为 yyyy/mm/dd IOS 系统的不同版本对 yyyy-mm-dd 格式的兼容性不同iphone13 的 16.3 版本支持 yyyy-mm-dd IOS 系统不支持日期的字符串拼接如 new Date(2023-10-10 00:00:00).getTime()如果需要设置年月日时分秒可以使用 setHours 等方法 const date new Date(2023-10-10).getTime();
date.setHours(0);3 代码示例
// 项目开始时间后台返回
const startTime 2023-10-12;// 第一版
// 效果12异常13正常
// iphone12 还有 0天 0小时 开始
// iphone13 还有 1天 8小时 开始
const beginTimeStamp new Date(${startTime} 00:00:00).getTime();
const currentTimeStamp Date.now();
const timePoint beginTimeStamp - currentTimeStamp; // 传递给CountDown组件// 第二版
// 效果12正常13异常
// iphone12 还有 1天 8小时 开始
// iphone13 还有 0天 0小时 开始
const timeStr startTime.replace(/-/g, /); // IOS不支持日期中的-需要将-替换为/
const beginTimeStamp new Date(${timeStr} 00:00:00).getTime();
const currentTimeStamp Date.now();
const timePoint beginTimeStamp - currentTimeStamp;// 第三版
// 效果12和13都正常
// iphone12 还有 1天 8小时 开始
// iphone13 还有 1天 8小时 开始
const timeStr startTime.replace(/-/g, /); // IOS不支持日期中的-需要将-替换为/
const beginDate new Date(timeStr);
beginDate.setHours(0); // IOS不支持字符串拼接需要调用setHours方法
const currentTimeStamp Date.now();
const timePoint beginTimeStamp - currentTimeStamp;