Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i need help with my clock

Hi !

 

I need help with my clock. I dunno how to put AM/PM with the preference setting

 

//****Clock*****//

// Update the clock every seconds
clock.granularity = 'seconds'; // seconds, minutes, hours

 

// Get a handle on the <text> element
const clockLabelStart = document.getElementById("clockLabelStart");

 

// Update the <text> element every tick with the current time
clock.ontick = function(evt) {
clockLabelStart.text = ("0" + evt.date.getHours()).slice(-2) + ":" +
("0" + evt.date.getMinutes()).slice(-2) + ":" ;

 

// Update the clock every seconds
clock.granularity = 'seconds'; // seconds, minutes, hours

// Get a handle on the <text> element
const clockLabelEnd = document.getElementById("clockLabelEnd");

 

// Update the <text> element every tick with the current time
clock.ontick = function(evt) {
clockLabelEnd.text = ("0" + evt.date.getSeconds()).slice(-2) ;

};

 

thanks in advance

Best Answer
0 Votes
1 REPLY 1

Generally I use the expression:

 

TDate.getHours() < 12 ? "am" : "pm"

 

Where tDate = new Date()

Best Answer
0 Votes