Updated:

1. Create a stopwatch

/stopwatch create race:time

Name it with a namespaced ID. It starts counting as soon as it is created.

2. Check the time

/stopwatch query race:time

Shows the elapsed seconds in chat. It counts real time, not game ticks, so the tick command and server lag do not change it.

3. Restart or remove

/stopwatch restart race:time
/stopwatch remove race:time

Put restart under the start pressure plate so each run starts at zero.

4. Save a lap time to a score

/scoreboard objectives add laptime dummy "Time (1/100 s)"
execute as @p store result score @s laptime run stopwatch query race:time 100

The final 100 is a scale: 12.345 seconds becomes 1234. See execute store.

5. Branch on elapsed time

execute if stopwatch race:time 60.. run title @a title {"text":"Time up!","color":"red"}

60.. means 60 seconds or more and ..30 means 30 or less. In a repeat block it fires every tick while true, so stop it with a tag.

6. Versus tick counting

Older timers add 1 per tick and divide by 20, which runs slow when the server lags. A stopwatch keeps real time, so use it for records, for example in parkour.

Troubleshooting

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.