Jump to content


API date return value has what format?

api created_at timestamp convert

  • Please log in to reply
2 replies to this topic

EifelDriver #1 Posted 17 July 2018 - 05:31 PM

    Private

  • Player
  • 6908 battles
  • 14
  • [-GT] -GT
  • Member since:
    12-08-2016

I receive via API the player data and have found the value 1531335384 in the field created_at.
But if I try to convert to the corresponding date 09.12.2016 , I dont have success.

 

new Date(1531335384)
Sun Jan 18 1970 18:22:15 GMT+0100 (Mitteleuropäische Normalzeit)
new Date(1531335384 * 1000)
Wed Jul 11 2018 20:56:24 GMT+0200 (Mitteleuropäische Sommerzeit)
new Date(1531335384 / 1000)
Thu Jan 01 1970 01:25:31 GMT+0100 (Mitteleuropäische Normalzeit)

 

How I have to use the value in the timestamp fields?

 

Thx.
EifelDriver


Edited by EifelDriver, 17 July 2018 - 05:34 PM.


lgfrbcsgo #2 Posted 17 July 2018 - 05:46 PM

    Second Lieutenant

  • Player
  • 30261 battles
  • 1,016
  • [MOTIV] MOTIV
  • Member since:
    04-04-2012

I am assuming you are using JavaScript? The time is returned as a UNIX timestamp in seconds, i.e., you have to multiply by 1000 when passing it to the Date constructor. Also don't forget the new statement.

 

new Date(1333548958 * 1000)
Wed Apr 04 2012 16:15:58 GMT+0200 (Mitteleuropäische Sommerzeit)

 

Edit: Are you sure you're working with the correct value? The corresponding UNIX timestamp for 09.12.2016 would be 1481238000.


Edited by lgfrbcsgo, 17 July 2018 - 05:59 PM.


EifelDriver #3 Posted 17 July 2018 - 05:58 PM

    Private

  • Player
  • 6908 battles
  • 14
  • [-GT] -GT
  • Member since:
    12-08-2016

Thx - I have a fundamental error in my situation.

 

The value 1531335384 was from another API request and represent not my target date 09.12.2016 - So I can't resolve my problem because I have used wrong values.

 

And you have right: new Date(value * 1000) represent the correct date.

 

Thx again.

EifelDriver







Also tagged with api, created_at, timestamp, convert

1 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users