9

I'm experimenting/learning with java and json. I'm trying to make my own data for a json parser and I can't figure out what datatype the example data it gives me is. I think it's a datetime, but I don't know how to get my date (regular format) to the json date format. I'm coding the example using PHP.

Jsonp Example Data:

[1110844800000,178.61],
[1110931200000,175.60],
[1111017600000,179.29],

My Date and Data format:

2012-03-01 18:21:31,42
2012-03-01 18:22:31,46
2012-03-02 18:21:31,40

Does anyone know if the 13 digit date/time json above is a datetime specific to java or json? And if so, how to get my data to that format?

Thanks!

CREW
  • 926
  • 3
  • 17
  • 32

4 Answers4

16

It looks like the Javascript version of Unix time, which is really just Unix time in milliseconds rather than seconds.

Divide your 13-digit numbers by 1000 and run them through this site to verify: http://www.onlineconversion.com/unix_time.htm

gregheo
  • 4,182
  • 2
  • 23
  • 22
7

Each of what you've quoted is an array with two entries. The first entry in each array might be a datetime. If so:

1110844800000 = Tue, 15 Mar 2005 00:00:00 GMT
1110931200000 = Wed, 16 Mar 2005 00:00:00 GMT
1111017600000 = Thu, 17 Mar 2005 00:00:00 GMT

JavaScript stores date/times as milliseconds since The Epoch (midnight on 1 Jan 1970 GMT), so to convert to Date instances:

var dt = new Date(1110844800000);

...which is how I got the values above.

No idea what the second entry in each array is. It looks like a currency (money) figure.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
1

‘-1110844800000’ is number of milliseconds from January 1, 1970 and ‘-178.61’ is time offset.

Anurag Ramdasan
  • 4,189
  • 4
  • 31
  • 53
0

Your first array is Unix Time in milliseconds like gregheo said.

If you want to convert your Unix timestamp in JAVA, you can find a good example there :

Convert UNIX Timestamp to DT

Community
  • 1
  • 1
ChapMic
  • 26,954
  • 1
  • 21
  • 20