TimeSpan ToString formating

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
Is there a format string that will convert a timespan to string that will display the hour if its more than 1hr and hide the hour if less than?

VB.NET:
TimeSpan.FromSeconds(3600).ToString("hh\:mm\:ss") '01:00:00
TimeSpan.FromSeconds(3599).ToString("mm\:ss") '59:59
 
Hi,

An If statement will do the job. Have a play with this example:-

For Counter As Integer = 1 To 10
  Dim someSeconds As Integer = 1000 * Counter
  MsgBox(TimeSpan.FromSeconds(someSeconds).ToString(If(someSeconds < 3600, "mm\:ss", "hh\:mm\:ss")))
Next


Hope that helps.

Cheers,

Ian
 
Back
Top