• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

os.time()

DedicatedOT

New Member
Joined
Jun 13, 2009
Messages
977
Reaction score
4
Location
USA
So suppose I have time_before and time_now, and time_difference.

time_difference = time_now - time_before,

How do I translate time_difference into seconds?


Thanks.
 
Lua:
	local left, h, m, s = time_difference, 0, 0, 0
	while left >= 3600 do
		left = left - 3600
		h = h + 1
	end
	while left >= 60 do
		left = left - 60
		m = m + 1
	end
	while left >= 1 do
		left = left - 1
		s = s+1
	end

There you go, :thumbup:.
 
It return this:
h = houres
m = minutes
s = seconds

If your "time_difference" is something like "6580" then the script cut it into pieces and cout them (h, m, s).

Code:
- left = 8580
-> 2x 3200 = (h = 2)
- left = 80
-> 1x 60 = (m = 1)
- left = 20
-> 20x 1 = (s = 20)

Result: h = 2, m = 1, s = 20, and you have your time different in houres, minutes, seconds.
 
os.difftime(t2, t1)

Calculate the number of seconds between time t1 to time t2.
> t1 = os.time()
> -- wait a little while then type....
> = os.difftime(os.time(), t1)
31
> = os.difftime(os.time(), t1)
38

:))
 
what you mean? os.time(t) it's a time in system seconds. I have no idea about Linux's ones...guess it will work same
 
How do you see how much time is left?
I forgot and I can't test it atm.

Code:
os.time() - getPlayerStorageValue(cid, cfg.storage)

You have 1 hour, 30 minutes, and 10 seconds left.
 
Last edited:
Sorry, to bump, but I kinda need this asap.
I keep messing with it, and it isn't working properly.
 
Back
Top