1***@qq.com
1***@qq.com
  • 发布:2019-09-07 13:52
  • 更新:2020-07-04 17:31
  • 阅读:9564

uniapp时间转换问题

分类:uni-app

uniapp转换时间格式, 正常运行状态下显示 NaN-NaN-NaN, 开启debug调试之后就显示正常了

转换方法

    Date.prototype.format = function(fmt) {  
    var o = {  
        "M+": this.getMonth() + 1, //月份   
        "d+": this.getDate(), //日   
        "h+": this.getHours(), //小时   
        "m+": this.getMinutes(), //分   
        "s+": this.getSeconds(), //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds() //毫秒   
    };  
    if (/(y+)/i.test(fmt))  
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
    for (var k in o) {  
        if (new RegExp("(" + k + ")").test(fmt)) {  
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));  
        }  
    }  
    return fmt;  
}

转换

   // log之后发现在运行状态下  new Date('2020-08-06T16:00:00.000+0000') 的值是 Invalid Date  
   new Date('2020-08-06T16:00:00.000+0000').format('YYYY-MM-dd')  
}

这种有点不明原因, 也不知道算不算是正常, 没有试过云打包之后的显示效果

2019-09-07 13:52 负责人:无 分享
已邀请:
重庆柔然科技

重庆柔然科技 - 短头发

原因是 IOS系统只识别 " / " 不识别 " - "

var date = "2019-8-14 10:03:45"  
//不兼容代码  
var newDate = new Date(date);  
//解决  
var newDate = new Date(date.replace(/-/g, '/'));
2***@qq.com

2***@qq.com

LZ解决了吗?

  • 1***@qq.com (作者)

    没有好的办法解决, 可能打包之后没有这个问题吧, 我没有测试, 直接让后台把时间转换之后给我了

    2019-11-28 12:01

1***@qq.com

1***@qq.com - cricklew

我也是这个问题
[图片]

该问题目前已经被锁定, 无法添加新回复