微信小程序,IOS兼容日期格式问题,注意ios高低版本兼容性不一致

问题描述:

今天调试代码的时候出现以下问题,在部分 iOS 下无法正常使用,iOS 只支持 "yyyy/MM/dd"、"yyyy/MM/dd HH:mm:ss"、"yyyy-MM-dd"、"yyyy-MM-ddTHH:mm:ss"、"yyyy-MM-ddTHH:mm:ss+HH:mm" 的格式当时页面展示时间格式为,yyyy-mm-dd hh:mm:ss。

解决方法:

修改为ios支持的时间格式 比如 yyyy/mm/dd hh:mm:ss ,例如如下时间格式转换 格式为

{year}/{month}/{day} {hours}:{minutes}:{seconds}

javascript 复制代码
export default function formatDate(dataStr) {
  const date = new Date(dataStr);
  if (!isNaN(date)) {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
  } else {
    // 无法解析日期,返回原始字符串或抛出错误,取决于需求
    return dataStr;
  }
}
相关推荐
咖啡の猫6 小时前
微信小程序WXSS 模板样式
微信小程序·小程序
AALoveTouch12 小时前
分享演唱会攻略-抢票利器
小程序·自动化
万岳科技系统开发13 小时前
开源上门预约系统源码,如何实现智能排班与时间冲突校验?
小程序·开源
说私域13 小时前
基于定制开发AI智能名片商城小程序的运营创新与资金效率提升研究
大数据·人工智能·小程序
qq_124987075315 小时前
基于微信小程序的宠物寄领养系统(源码+论文+部署+安装)
java·spring boot·后端·微信小程序·小程序·宠物·计算机毕业设计
咖啡の猫16 小时前
微信小程序页面配置
微信小程序·小程序·notepad++
2501_9160088916 小时前
iOS开发APP上架全流程解析:从开发到App Store的完整指南
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导617 小时前
基于微信小程序技术校园拼车系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
计算机毕设指导617 小时前
基于微信小程序求职招聘-兼职管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·求职招聘
咖啡の猫17 小时前
微信小程序全局配置
微信小程序·小程序