datetime - Convert MM:SS string to HH:MM:SS in C# -


i have piece of code works nicely convert hh:mm:ss seconds integer.

  (int = 0; < nrdaily.rows.count; i++)   {       double nrt = timespan.parse(nrdaily.rows[i][3].tostring()).totalseconds;       nrdaily.rows[i][3] = nrt;   } 

however, have csv file i'm dealing field has many values stored in mm:ss format , totalseconds seems misinterpret hh:mm , gives false result.

how check string see if it's in hh:mm:ss format, , if in mm:ss convert hh:mm:ss?

you check string length starters identify format.

for (int = 0; < nrdaily.rows.count; i++) {      string time = nrdaily.rows[i][3].tostring();      if (time.length == 5)           time = "00:" + time;      double nrt = timespan.parse(time).totalseconds;      nrdaily.rows[i][3] = nrt; } 

checking length simplistic approach. identify format more accurately, use regular expressions.