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

问题描述

要在JSON中向Web API传递时间或从Web API传递时间,为什么我选择使用ISO8601字符串而不是仅使用UTC纪元值?例如,这两个都是相同的:

For passing times in JSON to/from a web API, why would I choose to use an ISO8601 string instead of simply the UTC epoch value? For example, both of these are the same:

Epoch = 1511324473
iso8601 =   2017-11-22T04:21:13Z

历元值的长度显然较短,这对于移动数据的使用总是有利的,并且在历元值和语言的本地Date类型变量之间进行转换非常简单。

The epoch value is obviously shorter in length, which is always good for mobile data usage, and it's pretty simple to convert between epoch values and the language's local Date type variable.

我只是没有看到使用ISO字符串值的好处。

I'm just not seeing the benefit to using an ISO string value.

推荐答案

两者都是明确的,并且易于在程序中进行解析。就像您提到的那样,纪元的好处是它更小并且可以更快地在程序中处理。缺点是对人类没有任何意义。

Both are unambiguous and easy to parse in programs. The benefit of epoch like you have mentioned is that it is smaller and will be faster to process in your program. The downside is it means nothing to humans.

iso8901日期本身很容易阅读,不需要用户将数字转换为可识别的日期。与更大的图像(例如图像)相比,iso8601的尺寸增加并不明显。

iso8901 dates are easy to read on their own and don't require the user to translate a number in to a recognizable date. The size increase in iso8601 is unnoticeable when compared to much much larger things like images.

我个人会选择读取速度更快的API,因为它可以减少调试时间,同时检查发送和接收的值。在另一种情况下,例如在内部传递时间,您可能希望选择整数而不是文本的速度,因此取决于您认为哪个更有用。

Personally I would pick ease of reading over speed for an API as it will cut down on debugging time while inspecting values sent and received. In another situation such as passing times around internally you may wish to choose the speed of an integer over text so it depends which you think will be more useful.

这篇关于纪元或iso8601日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 05:09