GetTimeSeconds: Difference between revisions

From Onset Developer Wiki
REDRUM (talk | contribs)
mNo edit summary
No edit summary
Line 35: Line 35:
end
end
</syntaxhighlight>
</syntaxhighlight>
{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
*[[GetTimeSeconds]]
*[[GetDeltaSeconds]]
*[[GetTickCount]]

Revision as of 18:28, 30 August 2020

GetTimeSeconds

Type: Function
Context: Server & Client
Introduced: v1.0

Description

Returns the amount of time since the server started up.

Syntax

GetTimeSeconds()

Parameters

  • This function has no parameters.

Return Value

  • Returns a float value of the amount of time passed since the server started.

Example

AddCommand("uptime", function(player)
	if GetTimeSeconds() > 3600 then
		AddPlayerChat(player, "The server has been up for "..FormatTime(GetTimeSeconds()).." hours.")
	elseif GetTimeSeconds() > 60 then
		AddPlayerChat(player, "The server has been up for "..FormatTime(GetTimeSeconds()).." minutes.")
	else
		AddPlayerChat(player, "The server has been up for "..FormatTime(GetTimeSeconds()).." seconds.")
	end
end)

function FormatTime(seconds)
	local seconds = tonumber(seconds)
  
	if seconds <= 0 then
		return "00:00:00"
	else
		hours = string.format("%02.f", math.floor(seconds / 3600));
		mins = string.format("%02.f", math.floor(seconds / 60 - (hours * 60)));
		secs = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60));
		return hours..":"..mins..":"..secs
	end
end

See also