Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeSpan to ISO8601 duration format string

Tags:

c#

.net

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(); 
like image 926
garpunkal Avatar asked May 25 '10 15:05

garpunkal


1 Answers

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

   TimeSpan timeSpan = new TimeSpan(0, value, 0);    return XmlConvert.ToString(timeSpan); 
like image 80
garpunkal Avatar answered Oct 04 '22 11:10

garpunkal