On Tue, 27 Dec 2005 13:16:46 +0200, "Vadym Stetsyak" <va*****@ukr.net>
wrote:
TimeSpan span = TimeSpan.FromSeconds(3600);
string timeInterval = interval.ToString("HH:MM:SS");
That won't work. The ToString method of the TimeSpan
object does not take a format parameter, so it would
still be
Dim span As TimeSpan = TimeSpan.FromSeconds(iSeconds)
MsgBox(span.ToString())
But you are right: .FromSeconds is a more appropriate answer to
the original problem (though it looks as if FromSeconds requires
quite a bit more work to be performed under the covers). Ah, I'm
just nit-picking.
Have a look at the ToString function below (from Reflector).
A shorter, faster version could be written by hand to deal with
the specific requirement, but the formatting is the same as what
the original poster wanted:
---snip---
Public Overrides Function ToString() As String
Dim builder1 As New StringBuilder
Dim num1 As Integer = CType((Me._ticks / 864000000000), Integer)
Dim num2 As Long = (Me._ticks Mod 864000000000)
If (Me._ticks < 0) Then
builder1.Append("-")
num1 = -num1
num2 = -num2
End If
If (num1 <> 0) Then
builder1.Append(num1)
builder1.Append(".")
End If
builder1.Append(Me.IntToString(CType(((num2 / 36000000000) Mod
CType(24, Long)), Integer), 2))
builder1.Append(":")
builder1.Append(Me.IntToString(CType(((num2 / CType(600000000,
Long)) Mod CType(60, Long)), Integer), 2))
builder1.Append(":")
builder1.Append(Me.IntToString(CType(((num2 / CType(10000000,
Long)) Mod CType(60, Long)), Integer), 2))
Dim num3 As Integer = CType((num2 Mod CType(10000000, Long)),
Integer)
If (num3 <> 0) Then
builder1.Append(".")
builder1.Append(Me.IntToString(num3, 7))
End If
Return builder1.ToString
End Function
---snip---
/JB