Wrong date from timestamp

后端 未结 4 1462
独厮守ぢ
独厮守ぢ 2021-01-21 18:20

I have a problem which can\'t solve by myself.

Here is timestamp 1308085200 taken from my website database. It represents 2011-06-15 12:00:00

Here is javascrip

4条回答
  •  隐瞒了意图╮
    2021-01-21 18:39

    JavaScript's Date::getMonth() returns a zero-based integer from 0 to 11 which is why your date is showing May instead of June.

    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getMonth

    Update

    As for the time portion, this is what I get (AEST)

    var d = new Date(1308085200000); // Wed Jun 15 07:00:00 GMT+1000 (EST)
    d.toUTCString() // Tue, 14 Jun 2011 21:00:00 GMT
    d.getUTCFullYear() // 2011
    d.getUTCMonth() // 5
    d.getUTCDate() // 14
    d.getUTCHours() // 21
    d.getUTCMinutes() // 0
    d.getUTCSeconds() // 0
    

    Looks like your timestamp is actually not what you think it is.

提交回复
热议问题