ios 时间类型转换的问题
发布于 5 年前 作者 lei01 9826 次浏览 来自 问答

同求  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 回复

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

回到顶部