locked
Display format of Time Span RRS feed

  • Question

  • User1239610449 posted

    I have a value of 1.18.53.17 in a time span variable and I want this to display like this: 42:53:17 in hour:minutes:seconds (HH:MM:SS) format.

    Can anybody help me out that how can I display in the above format using vb.net?

    Tuesday, February 26, 2019 4:37 AM

Answers

  • User-893317190 posted

    Hi knowledgist,

    If you have a Timespan, you could use toString method to format the Timespan.

    Below is my code.

     Dim a As TimeSpan = New TimeSpan(1543970000000)
            Dim lessThanOneDay As String = a.ToString("hh\:mm\:ss")
         

    But in this way , you could only format Timespan less then one day. Because hh will not beyond 24.

    If you want to show hours more than 24, you could try the code below.

     Dim a As TimeSpan = New TimeSpan(1543970000000)
            Dim lessThanOneDay As String = a.ToString("hh\:mm\:ss")
           
            Response.Write((a.Days * 24 + a.Hours) & ":" & a.Minutes & ":" & a.Seconds)

    For more information about format TimeSpan , you could refer to https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings

    It is written in c# , you could use the website below to convert c# to vb.

    http://converter.telerik.com/

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 26, 2019 6:32 AM

All replies

  • User-893317190 posted

    Hi knowledgist,

    If you have a Timespan, you could use toString method to format the Timespan.

    Below is my code.

     Dim a As TimeSpan = New TimeSpan(1543970000000)
            Dim lessThanOneDay As String = a.ToString("hh\:mm\:ss")
         

    But in this way , you could only format Timespan less then one day. Because hh will not beyond 24.

    If you want to show hours more than 24, you could try the code below.

     Dim a As TimeSpan = New TimeSpan(1543970000000)
            Dim lessThanOneDay As String = a.ToString("hh\:mm\:ss")
           
            Response.Write((a.Days * 24 + a.Hours) & ":" & a.Minutes & ":" & a.Seconds)

    For more information about format TimeSpan , you could refer to https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings

    It is written in c# , you could use the website below to convert c# to vb.

    http://converter.telerik.com/

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 26, 2019 6:32 AM
  • User1239610449 posted

    Thanks buddy!

    Wednesday, February 27, 2019 4:38 AM