> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: Time
icon: clock
sidebar_position: 2
---

# <ApiPageIcon icon="clock" />Time

<Heading level={2} id="time-1">
  time

  <ApiTag label="global table" />
</Heading>

Gets the current time and runs functions after a delay. Scripts do not have the `os` library,
so use these functions to get the time.

<ApiMembers>
  <ApiMember kind="fn" name="time.GetEpochMilliseconds" summary="Returns the number of milliseconds since 1 January 1970, UTC." args="" sig="[{&#x22;s&#x22;:&#x22;time.GetEpochMilliseconds&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}]]" nodiscard />

  <ApiMember kind="fn" name="time.GetUnixTime" summary="Returns the number of seconds since 1 January 1970, UTC." args="" sig="[{&#x22;s&#x22;:&#x22;time.GetUnixTime&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}]]" nodiscard />

  <ApiMember kind="fn" name="time.GetLocalTime" summary="Returns the current local time of day as four numbers. These are the hour from 0 to 23, the minute, the second, and the millisecond from 0 to 999." args="" sig="[{&#x22;s&#x22;:&#x22;time.GetLocalTime&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" returns="[{&#x22;n&#x22;:&#x22;hour&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;minute&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;second&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;millisecond&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]}]" nodiscard />

  <ApiMember kind="fn" name="time.Format" summary="Formats a time as local time with a C `strftime` format string, for example `&#x22;%H:%M:%S&#x22;`." args="format, t?" sig="[{&#x22;s&#x22;:&#x22;time.Format&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;format&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;t&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;?&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;?&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;format&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The `strftime` format string.&#x22;},{&#x22;n&#x22;:&#x22;t&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}],&#x22;d&#x22;:&#x22;A Unix timestamp in seconds. If it is not given, the current time is used.&#x22;,&#x22;o&#x22;:true}]" nodiscard>
    <ApiNotes>
      Returns **nil** if the format uses a code that the Windows runtime does not know, such as `%P`,
      `%l` or `%-d`. Also returns **nil** if the time cannot be converted to local time, for example
      a negative timestamp.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="time.Schedule" summary="Runs a function once after a delay." args="delay, callback, ...?" sig="[{&#x22;s&#x22;:&#x22;time.Schedule&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;delay&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;number&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#number&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;callback&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;function&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#function&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;...&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;}]" params="[{&#x22;n&#x22;:&#x22;delay&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;number&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#number&#x22;}],&#x22;d&#x22;:&#x22;The delay in seconds.&#x22;},{&#x22;n&#x22;:&#x22;callback&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;function&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#function&#x22;}],&#x22;d&#x22;:&#x22;The function to run after the delay.&#x22;},{&#x22;n&#x22;:&#x22;...&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}],&#x22;d&#x22;:&#x22;The arguments to pass to the function.&#x22;,&#x22;o&#x22;:true}]">
    <ApiNotes>
      The delay is rounded down to whole milliseconds. A negative delay is treated as `0`. If
      `delay` is NaN, the function throws an error. A script can have at most 16384 scheduled calls
      that have not run yet. Past that, this function throws an error.

      Scheduled calls that have not run yet are dropped when the script shuts down.
    </ApiNotes>
  </ApiMember>
</ApiMembers>
