- Building Microservices with Go
- Nic Jackson
- 214字
- 2021-07-15 17:28:16
Dates
When returning a date, you should always use the DateLiteral format and preferably the Iso8601Literal. If you do need to send back a date in a format other than Iso8601Literal, then you can use a StructuredDateLiteral format, which allows you to specify the kind as part of the returned entity.
The informal Iso8601Literal format is the simplest method to use and should be understandable by almost any client consuming your API:
{"date": "2016-07-14T16:00Z"}
The more formal StucturedDateLiteral does not return a string, but an entity that contains two properties, kind and value:
{"date": {"kind": "U", "value": 1471186826}}
The permissible kinds are:
- C: CLR; number of milliseconds since midnight January 1 00
- E: ECMAScript; number of milliseconds since midnight, January 1, 1970
- I: ISO 8601; a string limited to the ECMAScript subset
- O: OLE Date; integral part is the number of days since midnight, December 31, 1899, and fractional part is the time within the day (0.5 = midday)
- T: Ticks; number of ticks (100-nanosecond intervals) since midnight January 1, 1601
- U: UNIX; number of seconds since midnight, January 1, 1970
- W: Windows; number of milliseconds since midnight January 1, 1601
- X: Excel; as for O, but the year 1900 is incorrectly treated as a leap year, and day 0 is "January 0 (zero)"
推薦閱讀
- Raspberry Pi Networking Cookbook(Second Edition)
- Dependency Injection in .NET Core 2.0
- Implementing Cisco Networking Solutions
- 從學徒到高手:汽車電路識圖、故障檢測與維修技能全圖解
- Apache Mahout Clustering Designs
- App Inventor創(chuàng)意趣味編程進階
- Flowable流程引擎實戰(zhàn)
- Qlik Sense? Cookbook
- Xamarin Blueprints
- Python開發(fā)基礎
- 從零開始學UI:概念解析、實戰(zhàn)提高、突破規(guī)則
- Java自然語言處理(原書第2版)
- Flask開發(fā)Web搜索引擎入門與實戰(zhàn)
- Elasticsearch搜索引擎構(gòu)建入門與實戰(zhàn)
- Responsive Web Design with jQuery