ios 时间类型转换的问题

发布于 7 年前作者 lei019993 次浏览最后编辑 7 年前来自 ask

同求  Java 返回的格林时间, 在ios上用普通的方法没法转换成时间戳 , 求解 @官方


var newDate = GMTToStr(2018-08-21T01:52:36.000+0000, 'Y/M/D h:m:s').replace(/-/g, '/')


function GMTToStr(time){

    console.log(time)

    let date = new Date(time)

    let Str = date.getFullYear() + '-' +

        (date.getMonth() + 1) + '-' +

        date.getDate() + ' ' +

        date.getHours() + ':' +

        date.getMinutes() + ':' +

        date.getSeconds()

        console.log(Str)

    return Str

}


ios返回null

1 回复
yandong
yandong1 楼5 年前

Note: parsing of date strings with the Date constructor (and Date.parse, they are equivalent) is strongly discouraged due to browser differences and inconsistencies. 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date