Abir John
Abir John

Reputation: 1

formet in 24 hour inn clock function

Hello every one I am writing a abir John and want to find the clock Javascript file

That's code add in javascript file then link in index.html file

function clock(){
var hour = document.getElementById('hour');
var minute = document.getElementById('minute');
var seconds= document.getElementById('seconds');
var amp= document.getElementById('amp');

if(h>12){
    h =h-12;

    var am = "PM"
} ```

Upvotes: 0

Views: 45

Answers (1)

Vishnu Satheesh
Vishnu Satheesh

Reputation: 313

I think you are trying to convert 24 hrs format to 12 hrs format. If you want to convert your hour to 12 hours format you can take % 12 on the current time.

If the time is 13 then 13 % 12 → 1

time = 23 then 23 % 12 → 11

time = 24, then 24 % 12 → 0, if the time is 0, then change the time as 12.

 if(h>=12){
   h = h%12 || 12;
}

Upvotes: 1

Related Questions