简体   繁体   中英

Adding a 0 to the Time in a VB Console Application

I have created a console application in VB.Net that adds 2 times together and then displays the output of the final time. I've managed to get it working after much work but I have a problem:

Sometimes when I calculate the time and the end result is below '10 mins', it doesn't include the "0" in front of the minutes. I say this because all numbers under 10 mins on a clock are like 09, 08, 07, etc..

For example, I do 2:05 + 1:02 which the answer is meant to be 3:07 instead it comes out as 3:7. Another example would be I do 1:00 + 2:00 and the output is 3:0 when its meant to be 3:00.

Can anyone help me figure out this problem?

Format the number using a custom format. Example:

Dim minuteString as String = minutes.ToString("00")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM