Legal characters in ISO sortable date format
What are the valid characters for an ISO date? I know of 0
through 9
, -
, :
, T
and Z
. Are there any more?
I obtain this sortable date fo开发者_JS百科rmat in .NET with .NET's XML serialization and like this:
var stringDate = myDateTime.ToString("s");
It looks like you can also have a W
as part of the ISO week date.
You can have a ,
or .
when dealing with decimal fractions that are added to a time element (See the times section here):
To denote "14 hours, 30 and one half minutes", do not include a seconds figure. Represent it as "14:30,5", "1430,5", "14:30.5", or "1430.5".
+
is valid when using them with UTC offsets such as 22:30+04
or 1130-0700
.
Durations can use a bunch of letters such as P
, Y
, M
, W
, D
, T
, H
, M
, and S
. They are a component of time intervals and define the amount of intervening time in a time interval.
Time intervals are the last one and can use /
to split a start and end time.
It looks like the default format when using the s
format string on a datetime is yyyy-MM-ddTHH:mm:ss"
, so the only valid characters in this case would be 0
to 9
, -
, :
and T
. The other characters above are part of the ISO 8601 standard which the sortable date/time pattern follows, but might not be applicable unless you deal with a different format string or culture.
精彩评论