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

Pubblicato il: 19 aprile 2022
sul canale di: 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


In questa pagina del sito puoi guardare il video online How to Make a Simple Digital Clock Using JavaScript | JavaScript Mini Project for Beginner | 2022 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Md Mehrab Patwary 19 aprile 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 400 volte e gli è piaciuto 13 spettatori. Buona visione!