【发布时间】:2016-05-13 07:34:33
【问题描述】:
我用谷歌搜索但找不到任何好的解决方案来验证输入字符串对于ISO Duration Format 是否正确,如果有人有任何想法或解决方案可能使用正则表达式或函数,将会有很大帮助。
注意:持续时间的格式为[-]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
.
【问题讨论】:
-
@WiktorStribiżew,我只想验证不转换的输入字符串
-
你写了 input string = "P100DT4H23M59S";预期输出 = 100 04:23:59.000000 - 这就是转换,不是吗?
-
@subodh 如果不解析则无效,不是吗?
标签: java regex string format duration