Display a clock time that updates

Looking to make a simple clock that displays the current time. I can get the timestamp just fine using new Date(); method, but I can’t seem to get it to update so that the seconds, minutes, etc. update.

Hi,
This post can help you:

1 Like

Thank you! I can’t get that to work at all though. For example,
let elapsedTime = timedEvent.getElapsedSeconds();
console.log("elapsed time " + elapsedTime);

doesn’t log anything at all.

If you mean a wall clock time, it’s

function update ()
{
    clock.setText(new Date().toLocaleTimeString());
}
1 Like

Samme was faster than me… here’s a way to do it with a timer

function create() {
  
  this.text = this.add.bitmapText(200, 128, 'desyrel', 'Game Clock:', 20).setOrigin(0.5, 0.5)
  
  const timedEvent = this.time.addEvent({
    delay: 1000,
    repeat: -1,
    callback: () => {
      let elapsedTime = new Date();
      let hour = elapsedTime.getHours();
      let minutes = elapsedTime.getMinutes();
      let seconds = elapsedTime.getSeconds();
      this.text.setText('Game Clock: ' + hour + ':' + minutes + ':' + seconds);
    }
  }); 
 
}

Thank you both!