Forum Discussion
Javascript for 12 hour clock
Hi! Thanks so much for the quick response. I'm not too familiar with java script so I was wondering how do i remove the seconds from the display?
I removed the sec from this line
player.SetVar("12Hour", hour+":"+minute+":"+sec+" "+am_pm);
And also i deleted this part of the code
var sec = date.getSeconds();
if(sec<10){
sec = "0"+sec;
}
So now the code looks like this
var player = GetPlayer();
function date_time() {
var date = new Date();
var am_pm = "AM";
var hour = date.getHours();
if(hour>=12){
am_pm = "PM";
}
if(hour>12){
hour = hour - 12;
}
if(hour<10){
hour = "0"+hour;
}
var minute = date.getMinutes();
if (minute<10){
minute = "0"+minute;
}
player.SetVar("12Hour", hour+":"+minute+am_pm);
}
setInterval(date_time,500);
But the seconds appears and disappears every second (refer to attached video).
How do I solve this issue?
Thanks again, you have been such a great help! :D
Hi,
I think your script is correct.
Anyway, use this script below.
var player = GetPlayer();
function date_time() {
var date = new Date();
var am_pm = "AM";
var hour = date.getHours();
if(hour>=12){
am_pm = "PM";
}
if(hour>12){
hour = hour - 12;
}
if(hour<10){
hour = "0"+hour;
}
var minute = date.getMinutes();
if (minute<10){
minute = "0"+minute;
}
player.SetVar("12Hour", hour+":"+minute+" "+am_pm);
}
setInterval(date_time,500);
- JingHerTan-58417 years agoCommunity Member
This is exactly what i wanted, thank you so much :D Have a great week!
Related Content
- 4 months ago