Calculate current tick() to GMT Time?

Hey!

I wonder if anyone in here managed to create a system that calculates tick() to full Hour:Minutes:Seconds in GMT-Time zone.

I couldn’t find any open resource scripts

2 Likes

The GMT timezone doesn’t have any time dfference between UTC. You can decide the current time by doing the math with the timestamp.

1 Like

not sure about tick(), but you can use the following:

local gmtTime = os.date("!*t", os.time()) 
print("Time: " ..  gmtTime.hour .. ":" .. gmtTime.min.. ":" .. gmtTime.sec)

os.date is explained on roblox’s website here

without any arguments, it returns the current date and time
you can see what the table contains in the link i sent you.

first parameter "!*t" gets the time in utc / gmt (theyre the same time) as a table
you can see what the table contains in the link i sent you.
second parameter is the time (in seconds). os.time() is the default time so technically we don’t need it there

if you wanted a different time zone: eg two hours ahead you’d make it
local myTime= os.date("!*t", os.time() + (3600 * 2))

5 Likes

Here’s my way of converting seconds into DHMS (and if the seconds don’t accumulate to an entire day, it returns HMS - if the seconds don’t accumulate to an entire hour, it returns MS, etc.):

function module:ConvertSecondsToDHMS(Seconds)
	local DHMS = ""
	if Seconds >= 86400 then
		DHMS = string.format("%02i:%02i:%02i:%02i", (Seconds / (24 * 3600)), ((Seconds % (24 * 3600)) / 3600), (Seconds / 60 % 60), (Seconds % 60))
	elseif Seconds >= 3600 then
		DHMS = string.format("%02i:%02i:%02i", (Seconds / 60 ^ 2), (Seconds / 60 % 60), (Seconds % 60))
	elseif Seconds >= 60 then
		DHMS = string.format("%02i:%02i", (Seconds / 60 % 60), (Seconds % 60))
	else
		DHMS = string.format("%02i", (Seconds % 60)) .." second".. (((Seconds % 60) == 0 or (Seconds % 60) > 1) and "s" or "")
	end
	if string.sub(DHMS, 1, 1) == "0" then
		DHMS = string.sub(DHMS, 2)
	end
	return DHMS
end

But like I said, this returns converted seconds. I’m sure you can mess around with the code to make it work with milliseconds.

2 Likes