So I'm trying to just get the hour it is(hour of the day) for example in eastern it is
6:31
as of the time posting this.
I'm trying to get the hours from unix time. Here is what I have done so far but i feel as it is innacurate and I am not sure where to go from here.
hourTime = ((tick() / 3600) % 12)
any help would be much appreciated :)
You're correct, (tick() / 3600) % 12
will return the correct hour of the day. The decimal places after that hour represent the percentage completed toward the next hour. In other words, the ratio of n
minutes to 60
. You could easily get the n
minutes you're looking for by multiplying 60
by the preceding decimals...
local function getHourWithMinutes() local hour, alpha = math.modf(tick() / 3600 % 12) local mins = alpha * 60 return string.format("%d:%d", hour, mins) end print(getHourWithMinutes())
8:17
You can get the current hour of the day by:
((tick()%86400)/3600)
An alternative is to use os.date:
local TIME = os.date(tick(), '!*t') print(TIME.hour)