时间跨度为ISO8601时间格式字符串 [英] TimeSpan to ISO8601 duration format string

查看:172
本文介绍了时间跨度为ISO8601时间格式字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以就如何转换时间跨度或INT到ISO8601时长串任何人提醒如 HTTP解释:?//en.wikipedia.org/wiki/ISO_8601#Durations

1小时30分钟会导致PT1H30M,例如:

  INT持续时间= 90;
字符串isoString = duration.ToIsoDuration();
 

解决方案

找到了解决办法我自己,所以我想我会分享:

 时间跨度时间跨度=新的时间跨度(0,值,0);
   返回XmlConvert.ToString(时间跨度);
 

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);

这篇关于时间跨度为ISO8601时间格式字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆