ISO 8601 represents a date as YYYY-MM-DD.

It doesn't seem to offer any recommendation on how to represent a date range, for example:

2013-01-01 => 2013-06-31

Does ISO 8601, or another standard, give a sensible recommendation for representing date ranges?

Background: this is to be used as the output of the toString() method of a DateRange object, output which could then be parsed with a parse() method.

有帮助吗?

解决方案

ISO 8601 does have a standard for representing date ranges. To represent the start and end date using this format you would write:

2013-01-01/2013-06-31

Note how the forward slash is used as the interval designator to separate the start and end dates.

See here for more information.

其他提示

Just to add to Ben Smith's answer above, the standard also mentions using a double hypen (--) as the interval designator in certain contexts, instead of the forward slash (/). For example, in file or directory names where using a forward slash is forbidden in some operating systems (e.g. Windows).

So the above examples would be

2013-01-01--2013-06-31

or

2013-01-01--06-31

in abbreviated form

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top