我谷歌搜索了一下,但是没有找到任何好的解决方案来验证输入字符串是否符合ISO持续时间格式。如果有人有任何想法或解决方案,可能使用正则表达式或函数,将会帮助很多人。
注意:持续时间的格式为
注意:持续时间的格式为
[-]P[n]DT[n]H[n]M[n][.frac_secs]S
,其中n指定元素的值(例如,4H表示4小时)。这表示ISO持续时间格式的一个子集,任何其他持续时间字母(包括有效的ISO字母,如Y和M)都会导致错误。Example 1,
input string = "P100DT4H23M59S";
expected output = 100 04:23:59.000000
Example 2,
input string = "P2MT12H";
expected output = error, because the month designator, '2M', isn't allowed.
Example 3,
input string = "100 04:23:59";
expected output = 100 04:23:59.000000
.