本文介绍了JSON日期说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我对正在查看的内容有些困惑.我正在使用PHP的json_encode函数和内置的MongoDB东西将MongoDate转换为JSON.结果是在返回的JSON字符串中的内容:

So, I'm a little bit confused by what I'm looking at. I'm converting a MongoDate to JSON using PHP's json_encode function and built-in MongoDB stuff. The result is this within my JSON string that's returned:

"date":{"sec":1344724737,"usec":0}}

我知道sec的值是UNIX纪元时间(更精确地说,是从1970年1月1日UTC的00:00:00开始的秒数).但是,我不知道usec的值是什么.是毫秒数的无符号整数值吗?我应该使用sec来获取值吗?作为记录,我将其转换为iOS应用程序中的NSDate.可以这样工作,但是我只是想了解更多这些值是什么,以确保我使用的是正确的值(因此一旦投入生产,我就可以在晚上入睡).

I understand the sec value is UNIX epoch time (seconds from 00:00:00 UTC on 1 January 1970 to be more precise). However, I don't know what the usec value is. Is it an unsigned integer value for the milliseconds? Should I be using sec to get the value? For the record, I'm converting this into an NSDate in an iOS application. It works that way, but I just like to know more about what these values are to make sure I am using the right one (and so I can sleep at night once it goes into production).

推荐答案

它是一个整数,对应于微秒(μsec)的数量.您将其除以1000000,然后将其添加到sec值中以获得完整的时间戳记.

It's an integer corresponding to the number of microseconds (μsec). You divide by 1000000 and add it to the sec value to get the full timestamp.

这篇关于JSON日期说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:57