Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7065881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:00:40+00:00 2026-05-28T05:00:40+00:00

I am trying to make a simple program to convert time given in seconds

  • 0

I am trying to make a simple program to convert time given in seconds to hh:mm:ss format. But for some particular input values it produces an incorrect time format. This is what I have tried:

Public Class Form1
    Dim Hours, Minutes, Seconds As Integer

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        lblHours.Text = "00"
        lblMinutes.Text = "00"
        lblSeconds.Text = "00"
        txtTimeSeconds.Text = ""
        txtFormattedTime.Text = ""
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate1.Click
        Seconds = Integer.Parse(txtTimeSeconds.Text)
        Hours = Seconds / 3600
        Seconds = Seconds Mod 3600
        Minutes = Seconds / 60
        Seconds = Seconds Mod 60

        lblHours.Text = Hours.ToString.PadLeft(2, "0"c)
        lblMinutes.Text = Minutes.ToString.PadLeft(2, "0"c)
        lblSeconds.Text = Seconds.ToString.PadLeft(2, "0"c)

        txtFormattedTime.Text = Hours.ToString.PadLeft(2, "0"c) & ":" & Minutes.ToString.PadLeft(2, "0"c) & ":" & Seconds.ToString.PadLeft(2, "0"c)
    End Sub
End Class

It works when the input value is 30:

Enter image description here

It does not work when the input value is 31:

Enter image description here

What have I done wrong? How can I fix this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:00:41+00:00Added an answer on May 28, 2026 at 5:00 am

    There is class in .NET called TimeSpan which makes your code easy and elegant.

    Example:

    dim iSecond as double = 0 'Total number of seconds
    Dim iSpan As TimeSpan = TimeSpan.FromSeconds(iSecond)
    
    lblHours.Text = iSpan.Hours.ToString.PadLeft(2, "0"c)
    lblMinutes.Text = iSpan.Minutes.ToString.PadLeft(2, "0"c)
    lblSeconds.Text = iSpan.Seconds.ToString.PadLeft(2, "0"c)
    
    txtFormattedTime.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & _
                            iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & _
                            iSpan.Seconds.ToString.PadLeft(2, "0"c)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make some simple XML with Java and org.w3c.dom, but I got
I am trying to make a simple time-calculating program in ASP.NET where people enter
Again, I'm trying to make a simple program. It will read some kind of
I'm trying to convert a simple C program into Python but as I don't
I'm trying to make a simple paint program in C#, but it keeps flickering
I am trying to make a simple program that handles files and directories, but
I'm new to iPhone programming, and I'm trying to make a simple program without
I'm trying to make a simple blackjack program. Sadly, I'm having problems right off
I'm trying to make a simple drawing app in c++, but i'm having trouble
i m trying to make a simple program ( & yes , it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.