Time Format RRS feed

  • General discussion

  •  i just want to use this format (hh:mm:ss) not (h:mm:ss) , this what i can't do in this application

    and this my code :

    Private Sub DisplayTime()
            Dim second As Integer
            Dim minute As Integer
            Dim hour As Integer
            Dim time As String ' the display String
            ' disallow extra input if number of hours > 9
            If timeString.Length > 5 Then
                ' take only the first 5 digits
                timeString = timeString.Substring(0, 5)
            End If
            ' pad the empty spaces of the display String with "0"
            time = timeString.PadLeft(5, Convert.ToChar("0"))
            ' extract seconds and minutes and hours
            second = Convert.ToInt32(time.Substring(3))
            minute = Convert.ToInt32(time.Substring(1, 2))
            hour = Convert.ToInt32(time.Substring(0, 1))
            ' create Time object to contain time entered by user
            cookTime = New Time(hour, minute, second)
            ' display number of hours, minutes, and seconds
            lblDisplay.Text = String.Format("{0:D1}:{1:D2}:{2:D2}", hour, minute, second)
        End Sub ' DisplayTime

    help me please

    Mohammad Khader

    Tuesday, October 16, 2012 3:42 PM

All replies

  • Hi Mohammad,

    You can use DateTieme.ToString to custom time format like this:

            Dim dateString As Date = "8:30:52 PM"
            Dim convertedTime As String
            convertedTime = dateString.ToString("hh:mm:ss") '08:30:52
            convertedTime = dateString.ToString("h:mm:ss") '8:30:52
            convertedTime = dateString.ToString("H:mm:ss") '20:30:52

    About Custom Date and Time Format Strings:http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx.

    Hope this helps.

    Best regards,

    Shanks Zen
    MSDN Community Support | Feedback to us

    Wednesday, October 17, 2012 7:19 AM