> For the complete documentation index, see [llms.txt](https://zarzel.gitbook.io/zarscript2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zarzel.gitbook.io/zarscript2/documentation/module/examples/time-counter.md).

# Time counter

This module will count the time it has passed since you joined a world with a new account

```lua
local prev_player_name = ""
local time = 0

local time_counter = {
    on_render_screen = function(ctx)
        if (player.name() ~= prev_player_name) then
            time = client.time()
            prev_player_name = player.name()
        end

        local diff = client.time() - time;
        if (diff > 0) then
            local diff_seconds = diff / 1000 % 60;
            local diff_minutes = diff / (60 * 1000) % 60;
            local diff_hours = diff / (60 * 60 * 1000) % 24;

            local string = math.floor(diff_hours) .. "h " .. math.floor(diff_minutes) .. "m " .. math.floor(diff_seconds) .. "s";
            render.string(string, ctx.width / 2 - render.get_string_width(string) / 2, 30, 255, 255, 255, 255)
        end
    end,
}

module_manager.register('TimeCounter', time_counter)
```
