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
Auf dieser Seite können Sie das Online-Video How to Make a Simple Digital Clock Using JavaScript | JavaScript Mini Project for Beginner | 2022 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Md Mehrab Patwary 19 April 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 400 Mal angesehen und es wurde von 13 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!