How to Make a Simple Digital Clock Using JavaScript | JavaScript Mini Project for Beginner | 2022

Publié le: 19 avril 2022
sur la chaîne: Md Mehrab Patwary
400
13

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


Sur cette page du site, vous pouvez voir la vidéo en ligne How to Make a Simple Digital Clock Using JavaScript | JavaScript Mini Project for Beginner | 2022 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Md Mehrab Patwary 19 avril 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 400 fois et il a aimé 13 téléspectateurs. Bon visionnage!