开发者

TimeSpan to ISO8601 duration format string

开发者 https://www.devze.com 2022-12-31 19:34 出处:网络
Can anyone advise on how to convert a timespan or int to an ISO8601 duration string as explained in http://en.wikipedia.org/wiki/ISO_8601#Durations?

Can anyone advise on how to convert a timespan or int to an ISO8601 duration string as explained in http://en.wikipedia.org/wiki/ISO_8601#Durations?

"1 hour and 30 minutes" would result in "PT1H30M", for example:

int duration = 90;
string isoString = duration.ToIsoDuration();
开发者_运维技巧


found the solution myself, so I thought I'd share:

   TimeSpan timeSpan = new TimeSpan(0, value, 0);
   return XmlConvert.ToString(timeSpan);


As the dupe question mentions LUIS, it can also produce more complex timex expressions.

One can generate or parse them using the same lib as LUIS uses: https://github.com/microsoft/Recognizers-Text

0

精彩评论

暂无评论...
验证码 换一张
取 消