Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there standard format for representing date/time in URIs?

Tags:

uri

datetime

api

I am building an API endpoint that accepts DateTime as a parameter.
It is recommended not to use : character as part of the URI, so I can't simply use ISO 8601 format.

So far I have considered two formats:

A) Exclamation mark as minute delimiter:

http://api.example.com/resource/2013-08-29T12!15

Looks unnatural and even with clear documentation, API consumers are bound to make mistakes.

B) URI segment per DateTime part:

http://api.example.com/resource/2013/08/29/12/15

Looks unreadable. Also, once I add further numeric parameters - it will become incomprehensible!

Is there standard/convention for for representing date/time in URIs?

like image 628
Arnold Zokas Avatar asked Aug 29 '13 11:08

Arnold Zokas


People also ask

What is the standard datetime format?

Thh. ISO 8601 uses the 24-hour clock system. As of ISO 8601-1:2019, the basic format is T[hh][mm][ss] and the extended format is T[hh]:[mm]:[ss].

What formats for displaying date and time?

The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.

Which of the following is the standard ISO 8601 format for dates?

ISO 8601 FormatsISO 8601 represents date and time by starting with the year, followed by the month, the day, the hour, the minutes, seconds and milliseconds. For example, 2020-07-10 15:00:00.000, represents the 10th of July 2020 at 3 p.m. (in local time as there is no time zone offset specified—more on that below).

What is the ISO standard for denoting time zones?

ISO 8601 can be used by anyone who wants to use a standardized way of presenting: Date. Time of day. Coordinated Universal Time (UTC)


2 Answers

I'd use the data interchange standard format.

Check this: http://en.wikipedia.org/wiki/ISO_8601

like image 136
Alberto Avatar answered Nov 29 '22 10:11

Alberto


You can use : in URI paths.

The colon is a reserved character, but it has no delimiting role in the path segment. So the following should apply:

If a reserved character is found in a URI component and no delimiting role is known for that character, then it must be interpreted as representing the data octet corresponding to that character's encoding in US-ASCII.

There is only one exception for relative-path references:

A path segment that contains a colon character (e.g., "this:that") cannot be used as the first segment of a relative-path reference, as it would be mistaken for a scheme name. Such a segment must be preceded by a dot-segment (e.g., "./this:that") to make a relative-path reference.

But note that some encoding libraries might percent-encode the colon anyway.

like image 43
unor Avatar answered Nov 29 '22 10:11

unor