How can I String.Format a TimeSpan object with a custom format in .NET?

后端 未结 19 1460
情深已故
情深已故 2020-11-22 12:25

What is the recommended way of formatting TimeSpan objects into a string with a custom format?

19条回答
  •  耶瑟儿~
    2020-11-22 12:59

    You can also go with:

    Dim ts As New TimeSpan(35, 21, 59, 59)  '(11, 22, 30, 30)    '
    Dim TimeStr1 As String = String.Format("{0:c}", ts)
    Dim TimeStr2 As String = New Date(ts.Ticks).ToString("dd.HH:mm:ss")
    

    EDIT:

    You can also look at Strings.Format.

        Dim ts As New TimeSpan(23, 30, 59)
        Dim str As String = Strings.Format(New DateTime(ts.Ticks), "H:mm:ss")
    

提交回复
热议问题