Skip to content

tw.date

Side: Shared (Client + Server)

Utilities for timestamps and duration formatting.

Functions

tw.date.now()

Returns the current time in milliseconds.

  • Server: uses os.time() * 1000
  • Client: uses GetGameTimer()

Returns: integer (milliseconds)


tw.date.format_duration(duration_ms, labels?)

Formats a duration in milliseconds into a human-readable string.

ParameterTypeDefaultDescription
duration_msintegerDuration in milliseconds
labelstable?See belowCustom labels for units

Labels table:

FieldTypeDefaultDescription
msstring"ms"Milliseconds unit
sstring"s"Seconds unit
minstring"min"Minutes unit
hstring"h"Hours unit
dstring"d"Days unit (singular)
dsstring"d"Days unit (plural)
separatorstring", "Separator between units
nowstring"now"Returned when duration is 0 or negative

Returns: string

Examples

lua
-- Current timestamp
local now = tw.date.now()

-- Format durations
tw.date.format_duration(9015000)
-- "2h, 30 min, 15 s"

tw.date.format_duration(500)
-- "500 ms"

tw.date.format_duration(0)
-- "now"

tw.date.format_duration(90061000)
-- "1 d, 1h, 1 min, 1 s"

-- Custom labels (French)
tw.date.format_duration(9015000, {
    h = "heure(s)",
    min = "minute(s)",
    s = "seconde(s)",
    separator = " et ",
})
-- "2 heure(s) et 30 minute(s) et 15 seconde(s)"

Premium RedM Scripts — Multi-Framework