Json/Java 新手 - 这是什么数据类型?约会时间?13 位长。使用 PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9691319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
New to Json/Java - what datatype is this? A datetime? 13 digits long. Using PHP
提问by CREW
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.
我正在试验/学习 java 和 json。我正在尝试为 json 解析器创建自己的数据,但我无法弄清楚它给我的示例数据是什么数据类型。我认为这是一个日期时间,但我不知道如何将我的日期(常规格式)转换为 json 日期格式。我正在使用 PHP 编写示例代码。
Jsonp Example Data:
Jsonp 示例数据:
[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?
有谁知道上面的 13 位日期/时间 json 是特定于 java 还是 json 的日期时间?如果是这样,如何将我的数据转换为该格式?
Thanks!
谢谢!
采纳答案by gregheo
It looks like the Javascript version of Unix time, which is really just Unix time in milliseconds rather than seconds.
它看起来像Unix time的 Javascript 版本,它实际上只是以毫秒而不是秒为单位的 Unix 时间。
Divide your 13-digit numbers by 1000 and run them through this site to verify: http://www.onlineconversion.com/unix_time.htm
将您的 13 位数字除以 1000 并通过此站点运行以进行验证:http: //www.onlineconversion.com/unix_time.htm
回答by Anurag Ramdasan
‘-1110844800000' is number of milliseconds from January 1, 1970 and ‘-178.61' is time offset.
'-1110844800000' 是从 1970 年 1 月 1 日起的毫秒数,'-178.61' 是时间偏移量。
回答by T.J. Crowder
Each of what you've quoted is an array with two entries. The first entry in each array mightbe 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:
JavaScript 将日期/时间存储为自大纪元(格林威治标准时间 1970 年 1 月 1 日午夜)以来的毫秒数,因此要转换为Date
实例:
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.
不知道每个数组中的第二个条目是什么。它看起来像一个货币(钱)数字。
回答by ChapMic
Your first array is Unix Time in milliseconds like gregheo said.
您的第一个数组是以毫秒为单位的 Unix 时间,如 gregheo 所说。
If you want to convert your Unix timestamp in JAVA, you can find a good example there :
如果你想在 JAVA 中转换你的 Unix 时间戳,你可以在那里找到一个很好的例子: