3

In The YouTube v3 Developer API, when retrieving the video duration it's returned in ISO 8601 format.

How can I parse this as a DateTime object in C#?

Here's an example: PT5M58S

James Wilkinson
  • 185
  • 2
  • 12

1 Answers1

3
TimeSpan ts = XmlConvert.ToTimeSpan("PT5M58S");

Best option is to convert to a TimeSpan instead of a DateTime.

From the MS docs on TimeSpan (https://msdn.microsoft.com/library/system.timespan):

Represents a time interval.

Filipe Borges
  • 2,712
  • 20
  • 32