Commands/stopwatch

Minecraft Wiki article. Categories: Java_Edition, Commands

📌 Mirrored from Minecraft Wiki

This article is reproduced from Commands/stopwatch on the Minecraft Wiki. Mirrored from revision 3725573. It is licensed CC BY-NC-SA 3.0 by the Minecraft Wiki contributors — not under the Codex’s CC BY-SA 4.0, and it may not be used commercially. Edits belong upstream, not here.

This feature is exclusive to Java Edition.
 
/stopwatch

Allows manipulation of stopwatches to keep track of real time — the time measured is not affected by the game's tick rate (i.e. pausing, /tick, or even server lag). This makes it useful to detect and compensate for lag e.g. when programming functions in a data pack.

Usage

The time is calculated with millisecond precision. Therefore:

  • When displayed, it is presented in seconds with 3 decimal places (e.g. 43.961s).
  • While any number can be used as the scale argument, a scale with a value >1000 is not useful to extract additional precision in the integer return value.

Syntax

/stopwatch ...

... create <id> - Creates a stopwatch, which immediately begins running
... query <id> [<scale>] - Gets the value of the stopwatch, the amount of time since it was created/restarted in seconds.
... restart <id> - Restarts a stopwatch
... remove <id> - Removes a stopwatch

Arguments

<id>: resource_location

Specifies the stopwatch to operate on.
Must be a resource location for an unregistered content.

<scale>: double

Specifies the value to multiply the returned value by, e. g. stopwatch query foo:bar 20 would get the elapsed time in ticks[1]. Does not affect the value displayed in chat. If the return value would exceed 32-bit signed integer limits (<-2147483648 or >2147483647), it is clamped.

Result

CommandTriggerJava Edition
AnyThe command is incomplete, or any argument is not specified correctly. Unparseable
stopwatch create ...The specified stopwatch already exists. Failed
stopwatch query ...The specified stopwatch doesn't exist.
stopwatch restart ...The specified stopwatch doesn't exist.
stopwatch remove ...The specified stopwatch doesn't exist.
AnyOtherwiseSuccessful

Output

CommandEditionSituationSuccess Count/execute store success .../execute store result ...
AnyJava EditionOn fail000
stopwatch create ...On success111
stopwatch query ...On success11The value of the stopwatch, multiplied by <scale>, then floored
stopwatch restart ...On success111
stopwatch remove ...On success111

History

Java Edition
1.21.1125w41aAdded /stopwatch.
25w42aSwitched the order of the id argument.
query now returns the queried value.
Added the scale argument to query.

Sources