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{
"title": "<code>/stopwatch</code>",
"rows": [
{
"field": "2",
"label": "(link to Permission level article, displayed as Permission level<br>required)"
},
{
"field": "None",
"label": "(link to Commands#Restrictions article, displayed as Restrictions)"
}
],
"invimages": [],
"images": []
}
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
scaleargument, ascalewith 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 20would 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
| Command | Trigger | Java Edition |
|---|---|---|
| Any | The 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. | |
| Any | Otherwise | Successful |
Output
| Command | Edition | Situation | Success Count | /execute store success ... | /execute store result ... |
|---|---|---|---|---|---|
| Any | Java Edition | On fail | 0 | 0 | 0 |
stopwatch create ... | On success | 1 | 1 | 1 | |
stopwatch query ... | On success | 1 | 1 | The value of the stopwatch, multiplied by <scale>, then floored | |
stopwatch restart ... | On success | 1 | 1 | 1 | |
stopwatch remove ... | On success | 1 | 1 | 1 |
History
| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.21.11 | 25w41a | Added /stopwatch. | |||||
| 25w42a | Switched the order of the id argument. | ||||||
query now returns the queried value.
| |||||||
Added the scale argument to query. | |||||||
Navigation
Sources
- Commands/stopwatch — Minecraft Wiki, CC BY-NC-SA 3.0, revision 3725573.