# Get server time from clients

**URL:** <https://forum.heroiclabs.com/t/get-server-time-from-clients/64>\
**Category:** Local Setup\
**Tags:** getting-started\
**Created:** [July 10, 2019, 7:41am UTC](https://forum.heroiclabs.com/t/get-server-time-from-clients/64 "2019-07-10T07:41:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Excess](https://avatars.discourse-cdn.com/v4/letter/e/9f8e36/32.png) [@Excess](https://forum.heroiclabs.com/u/Excess)\
**Post date:** [July 10, 2019, 7:41am UTC](https://forum.heroiclabs.com/t/get-server-time-from-clients/64/1 "2019-07-10T07:41:16Z")

</div>

Hi

Is there a way to get a time stamp from the server on the client side (javascript)?  
I could only find Lua and Go examples in the docs which I guess should be run on the server side.

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [July 10, 2019, 9:24am UTC](https://forum.heroiclabs.com/t/get-server-time-from-clients/64/2 "2019-07-10T09:24:27Z")

</div>

If you need to get the server time from the client you should register an [RPC hook](https://heroiclabs.com/docs/runtime-code-basics/#rpc-hook) with the appropriate Lua or Go code to capture server time and return it in the RPC response to the client.

Call that function in your client (in your case use `client.rpcGet()` in the JS client) and extract the time from the response.

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [July 10, 2019, 8:24pm UTC](https://forum.heroiclabs.com/t/get-server-time-from-clients/64/3 "2019-07-10T20:24:03Z")

</div>

An example of what the code could look like in Lua that would return the server time (UNIX time) as a response and register it with the server runtime:

```lua
local nk = require("nakama")

local function getservertime(context, payload)
    local resp = {
        current_time = os.time()
    }
    return nk.json_encode(resp)
end
nk.register_rpc("GetServerTime", getservertime)

```

---

<div class="post-metadata">

**Author:** ![Excess](https://avatars.discourse-cdn.com/v4/letter/e/9f8e36/32.png) [@Excess](https://forum.heroiclabs.com/u/Excess)\
**Post date:** [July 11, 2019, 12:43pm UTC](https://forum.heroiclabs.com/t/get-server-time-from-clients/64/4 "2019-07-11T12:43:50Z")

</div>

Thanks for the replies 👍

---

<div class="post-metadata">

**Author:** ![Mohammed](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@Mohammed](https://forum.heroiclabs.com/u/Mohammed)\
**Post date:** [December 28, 2019, 5:35pm UTC](https://forum.heroiclabs.com/t/get-server-time-from-clients/64/5 "2019-12-28T17:35:54Z")

</div>

```auto
os.time()

```

will give time in seconds. Is there a possible way to get it in milliseconds?

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 28, 2019, 5:40pm UTC](https://forum.heroiclabs.com/t/get-server-time-from-clients/64/6 "2019-12-28T17:40:36Z")

</div>

@Mohammed We have a helper function on the Nakama module in the Lua runtime.

```lua
local nk = require("nakama")
print(nk.time()) -- prints time in milliseconds since UNIX epoch

```

You can find it in the function reference:

[https://heroiclabs.com/docs/runtime-code-function-reference/#time](https://heroiclabs.com/docs/runtime-code-function-reference/#time)

---

<div class="post-metadata">

**Author:** ![Mohammed](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@Mohammed](https://forum.heroiclabs.com/u/Mohammed)\
**Post date:** [December 28, 2019, 5:42pm UTC](https://forum.heroiclabs.com/t/get-server-time-from-clients/64/7 "2019-12-28T17:42:57Z")

</div>

you 're a lifesaver man, I owe you big time
