# Clarification on "if" statement - Digital Clock Tutorial C# [closed]

I am building a digital clock in C# after watching a tutorial. The code in the tutorial I need help understanding looks like this:

if (hh < 10) {
time += "0" + hh;
}
else {
time += hh;
}
time += ":";


Can anyone explain to me why hh < 10? Should it not be at least 12?

My end game is to make a timer that starts at 9am and stops at 5pm. Ongoing applications under development. Looking at time money management.

• ps, "time" is a string, hh is an int representing the DateTime function. Commented Nov 3, 2019 at 11:36
• The purpose of that code snippet seems to prefix a '0' character for any hour lower than 10 for representation. Nothing to do with the 12 hour clock cycle. Commented Nov 3, 2019 at 11:44
• If this isn't your code, then I'm afraid this is off-topic. It's also off-topic, because we can't help with explaining how code works: we only review concrete, working code, which the OP already understands. See the help center for more information. Commented Nov 3, 2019 at 12:34
• Never mind. I fixed the solution using two different int values for time then comparing these with an if statement. Commented Nov 3, 2019 at 12:44
• @SamuelJosling Please delete your question, it's blatantly off-topic here. Commented Nov 3, 2019 at 14:08

## 1 Answer

Welcome to Codereview.
As I can see you are having troubles understanding the line that adds a "0" in front of hh. Let's say hh is 9. Then, as 9 is smaller than 10, time will be "09", if hh is "10", or greater, it won't add that "0" at the beginning.
After that (time += ":"), the program will add a ":" which would represent the hours in the clock and a ":" character afterwards, like "10:" or "09:".
So, When it adds the minutes, the algorithm will use a similar if statement, like this:

if (hh < 10) {
time += "0" + hh;
}
else {
time += hh;
}
time += ":";
if (mm < 10) {
time += "0" + mm;
}
else {
time += mm;
}


at the end the time that will be shown, will look something like "09:09", and such.