How to Make a Simple Digital Clock Using JavaScript:
Create a "Date()" object. From this object, you will get hours, minutes, and seconds. To set AM and PM, if the hour is greater than or equal to 12 that will be PM, otherwise AM.
To convert 24 hours times format to 12 hours format you need to do this stuff:
hours = hours % 12;
hours = hours ? hours : 12;
Now I will explain this code.
Suppose the hour is 17,
For this situation:
hours = 17 % 12; //Output is: 5
hours = 5 ? 5 : 12; //Output is 5
Again, Suppose the hour is 12,
For this situation:
hours = 12 % 12; //Output is: 0
hours = 0 ? 0 : 12; //Output is 12
Last of all, to update every second you need to use the "setTimeout()" function. This function will call the "showTime()" function every second.
Note: 1000 mili seconds = 1 Second
Tag:
html
javascript
JavaScript Mini Project
simple digital clock using javaScript
Nesta página do site você pode assistir ao vídeo on-line How to Make a Simple Digital Clock Using JavaScript | JavaScript Mini Project for Beginner | 2022 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Md Mehrab Patwary 19 Abril 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 400 vezes e gostou 13 espectadores. Boa visualização!