GetRealTime: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">table getRealTime( [int seconds = current] )</syntaxhighlight>
<syntaxhighlight lang="lua">table getRealTime( [int seconds = current] )</syntaxhighlight>
===Optional Arguments===
{{OptionalArg}}
{{New feature/item|3|1.0||
*'''seconds:''' A count in seconds from the year 1970.  Useful for storing points in time, or for retrieving time information for [[getBanTime]]. The valid range of this argument is 0 to 32,000,000,000
}}


===Returns===
===Returns===
Returns a ''table'' of substrings with different time format, ''false'' otherwise.
Returns a ''table'' of substrings with different time format or ''false'' if the '''seconds''' argument is out of range.


{| border="2" cellpadding="2" cellspacing="0" style="margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;"
{| border="2" cellpadding="2" cellspacing="0" style="margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;"
Line 53: Line 59:
|}
|}
* tm_sec is generally 0-59. Extra range to accommodate for leap seconds in certain systems.
* tm_sec is generally 0-59. Extra range to accommodate for leap seconds in certain systems.
===Optional Arguments===
{{OptionalArg}}
{{New feature/item|3|1.0||
*'''seconds:''' A count in seconds from the year 1970.  Useful for storing points in time, or for retrieving time information for [[getBanTime]].
}}


==Example==
==Example==

Revision as of 11:32, 27 November 2013

This function gets the real server time and returns it in a table. If you want to get the in-game time (shown on GTA's clock) use getTime.

Syntax

table getRealTime( [int seconds = current] )

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • seconds: A count in seconds from the year 1970. Useful for storing points in time, or for retrieving time information for getBanTime. The valid range of this argument is 0 to 32,000,000,000

Returns

Returns a table of substrings with different time format or false if the seconds argument is out of range.

Member Meaning Range
second seconds after the minute 0-61*
minute minutes after the hour 0-59
hour hours since midnight 0-23
monthday day of the month 1-31
month months since January 0-11
year years since 1900
weekday days since Sunday 0-6
yearday days since January 1 0-365
isdst Daylight Saving Time flag
timestamp seconds since 1970 (MTA 1.1 +)
  • tm_sec is generally 0-59. Extra range to accommodate for leap seconds in certain systems.

Example

This example outputs local time (server or client, where ever it was triggered) as hours and minutes

function showtime ()
	local time = getRealTime()
	local hours = time.hour
	local minutes = time.minute
	outputChatBox ( "Local Time: "..hours..":"..minutes )
end

See Also