Wrong timestamp using API

Gael Poffet shared this question 10 years ago
Answered

Hello,

I'm developping a small script to grab information from my Zipabox using the API and PHP.Everything works fine except the timestamp:All the timestamp are wrong. Exemple run today: the date and time corresponding to this timestamp (1385037315363) is 18/3/2035 à 16:54:11 which is of course impossible. The problem is the same for all meters.

  1. "cc5d896e-c2c4-4648-b7a5-3fd46cdf53d5" : { "name" : "Exterieur - Vent", "endpoint" : "e1ffbb26-5613-4687-b364-d26239286700", "uiType" : "METER", "description" : "", "iconName" : "Wind sensor", "iconType" : "sensor.wind", "attributes" : { "96" : { "id" : 96, "name" : "value2", "type" : "DOUBLE", "definition" : { "name" : "AVERAGE WIND SPEED", "unit" : "m/s", "type" : "Double", "scale" : 1.0 }, "timestamp" : 1385037315363, "value" : "0.0" },

Any idea ? Is is a bug or a wrong usage of timestamp ?Thanks for help.

Replies (4)

photo
1

And how did you get 2035-03-18 16:54:11?

Because that timestamp would be 2013-11-21 12:35:15.363

photo
1

I got this date using this PHP command:


$update = date('Y-m-d H:i:s', $timestamp);


How did you transform the TS to get today date ? Which language/function ?

photo
2

I used JavaScript Date function.

PHP date is returning 45860-02-01 12:36:03 because our timestam is in miliseconds and php date uses seconds so you just need to get date like this:

$update = date('Y-m-d H:i:s', $timestamp/1000);

photo
1

Perfect, it works.

Thanks for your help.

Leave a Comment
 
Attach a file