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

Published: 19 April 2022
on channel: 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


On this page of the site you can watch the video online How to Make a Simple Digital Clock Using JavaScript | JavaScript Mini Project for Beginner | 2022 with a duration of hours minute second in good quality, which was uploaded by the user Md Mehrab Patwary 19 April 2022, share the link with friends and acquaintances, this video has already been watched 400 times on youtube and it was liked by 13 viewers. Enjoy your viewing!