javascript 招摇和日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26884286/
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
Swagger and Date
提问by MemLeak
I'm new to swagger and writing my first spec. I've found following swagger "date" types*:
我刚开始大摇大摆地编写我的第一个规范。我发现以下大摇大摆的“日期”类型*:
------------------------------------------------
| Common name | Swagger spec 1.2 |
------------------------------------------------
| string | string |
------------------------------------------------
| date | string, date |
------------------------------------------------
| dateTime | string, date-time |
------------------------------------------------
Now my timestamp looks like 2014-12-09T13:06:08.260+0000
is this even a Date? It doens't look like the date javascript new Date();
returns. I also haven't found a date type in the json specification.
现在我的时间戳看起来2014-12-09T13:06:08.260+0000
甚至是日期?它看起来不像 javascriptnew Date();
返回的日期。我也没有在json 规范中找到日期类型。
Which type and format should i take, will it be better to take string instead of a date??
我应该采用哪种类型和格式,采用字符串而不是日期会更好吗??
*: note this table is the short version from the swager wiki
*:请注意此表是来自swager wiki的简短版本
回答by Dmitry
2014-12-09T13:06:08.260+0000
is a variation of ISO8601date and time standard. JavaScript Date
function can easily parse this format and Date
has toISOString()
method to produce strings in this format. The only thing is that letter "Z"is usually used to denote GMT/UTC time zone instead of "+0000". But Date
can parse it like that too.
2014-12-09T13:06:08.260+0000
是ISO8601日期和时间标准的变体。JavaScriptDate
函数可以轻松解析此格式,并Date
具有toISOString()
生成此格式字符串的方法。唯一的问题是字母"Z"通常用于表示 GMT/UTC 时区而不是"+0000"。但Date
也可以这样解析。