0

i have this javascript that displays a clock. Is it also possible that it display realtime an div on special time?

if (today >= 12 && today <= 13.30) {
    document.body.className += 'lunchbreak';
} else {
    document.body.className += 'nolunchbreak';
}

Used clock javascript:

    function timepadding(x5) {
  if (typeof x5 !== "string") {
    x5 = x5.toString()
  }
  var x6 = 0;
  var x7 = 0;
  if (x5 % 60 === 0) {
    return x5 + ":00"
  }
  else {
    x6 = x5 % 60;
    return x6.toString()
  }
}
function gettimezone() {
  var d = new Date();
  var z = document.getElementById("result");
  var utcsinceepoch = Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
  var y1 = d.getTime()
  z.innerHTML= (utcsinceepoch - d.getTime())/3600000;
}
gettimezone();
function utcoffset(time, offset) {
  return time + offset;
}
function displayTime() {
  var d = new Date();
  var y = document.getElementById("a");
  var h = (d.getHours()).toString();
  var m = (d.getMinutes()).toString();
  var s = (d.getSeconds()).toString();
  var h2 = ("0" + h).slice(-2);
  var m2 = ("0" + m).slice(-2);
  var s2 = ("0" + s).slice(-2);
  y.style.fontSize = "100px";
  y.innerHTML= h2 + ":" + m2 + ":" + s2;
}
setInterval(displayTime, 1000);

I hope you have ideas :)

https://jsbin.com/xubimewoke/edit?html,js,output

  • `className += 'lunchbreak'` you add but you never remove that class. Somewhen the body will have both classes – Jonas Wilms Mar 13 '18 at 14:52
  • Possible duplicate of [Displaying clock in div with javascript](https://stackoverflow.com/questions/47930156/displaying-clock-in-div-with-javascript) – Stefan Crain Mar 13 '18 at 15:00
  • Not sure what you are trying to do, do you want to add/remove some class at a specific time ? Put this code then in `displayTime` function, and not forget to remove previous `class` that you already set, as it mentioned in the comment above – Telman Mar 13 '18 at 15:11
  • Than i get something like this? https://jsbin.com/xubimewoke/edit?html,js,output Only it does not display the lunchbreak div between time (and cannot add second?) – PhanToM-the Mar 13 '18 at 15:44

0 Answers0