getRealTime | Multi Theft Auto: Wiki Skip to content

getRealTime

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function gets the server or client (if used client sided it returns time as set on client's computer) real time and returns it in a table. If you want to get the in-game time (shown on GTA's clock) use getTime.

Note

The seconds parameter can be left out entirely while still using the localTime parameter. To achieve that simply pass the boolean localTime parameter as first argument where you would otherwise pass the seconds parameter. This way you can retrieve a current timepoint that is not denoted in local time.

Syntax

getRealTime ( )

Code Examples

server

This example adds 'showtime' like the default MTA 'time' command:

function showtime ()
local time = getRealTime()
local hours = time.hour
local minutes = time.minute
local seconds = time.second
-- use string.format to keep it 2 digits. eg 1 will be converted to 01
outputChatBox ( string.format("Local Time: %02d:%02d:%02d", hours, minutes, seconds) )
end
addCommandHandler("showtime", showtime)