hey everyone today i’m going to show you how

to make a digital timer in Java so this is the finished project if i run it it counts seconds minutes and hours so let’s start at the beggining we’re gonna start by using the timer class so.. i’ve already imported that here and we’re gonna need a timer task so.. and.. here we make the function that the timer runs

every second and then.. we’re gonna use the schedule function

of the timer class to run the timer every second we wanna count seconds so we’re gonna make

a function for that i want three arguments one is the task that we just made and this argument is the timer that passes

before the timer starts i’m gonna put zero and this is the time between each excution

i want one second because i’m going to count seconds so.. now i need to make an instance of this class first then call that function now it’s not gonna do anything because i didn’t

put anything here so i’m gonna make a variable for the seconds i’m going to increment that here so it increments every second and then print

it out and run so now it counts seconds 1, 2, 3, 4.. but

i want to convert these seconds to second minute hour so i’m gonna do that right now so this function that i just pasted is gonna

take seconds that the timer counts in this case it’s this variable i and convert them

to this second minute hour string so in this function we have and integer for

hours minutes and seconds and we have three conditions first, if we have more than or

equal to one hour second, if we have more than or equal to a minute and.. third condition

is if we have less than 60 seconds so the first condition we calculate how many hours

by dividing that number by 3600 and then get the remainder of this division and then we

check if that remainder is more than or equal to a minute if it is then we calculate how

many minutes by dividing that number by 60 and how many seconds by getting the remainder

of that division if we have less than 60 seconds then we set our seconds to that remainder

and in this case we don’t have any minutes second condition is if we have more than or

equal to 60 seconds we’re gonna set hours to 0 and calculate minutes by dividing by

60 and seconds is the remainder of this division and third condition is if we have less than

60 seconds then hours is equal to zero minutes is equal to zero and seconds we just have

seconds in this case so we set our seconds to this value so we can call this done this

additional code is responsible for this zero that if we have a number less than 10 then

we’re gonna have a zero here and if the number is 10 or more this zero is gonna be replaced

by the number so if we run we’re gonna put this in the run function so ok if we run it’s

not working i don’t know why oh yeah because i want to start with a zero so i we run you can see

it works and if we have more than 10 or more this zero is gonna be replaced so that’s all for this tutorial if you found

this useful like or subscribe