Displaying a timer in mm:ss format online (optimization)

I use:

newTime = (exptTime - timeStart.getTime());
if ((newTime < 0)) {
    newTime = 0;
}
mins = Math.floor((newTime / 60));
secs = (newTime % 60);
if ((newTime !== oldTime)) {
    clock_time.text = ((Number.parseInt(mins).toString().padStart(2,"0") + ":") + Number.parseInt(secs).toString().padStart(2,"0"));
  oldTime = newTime;
}

The first block is auto translated from Python but the second needs a Both component. The Python version is:

if newTime != oldTime:
    clock_time.text=str(int(mins)).zfill(2) + ':' + str(int(secs)).zfill(2)
    oldTime = newTime

1 Like