• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Compare OS time on lua.

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,764
Solutions
1
Reaction score
227
Location
Chile, Santiago
I found getWorldTime() but can't test right now what returns... If anyone knows, would be cool if him answer me!
Another thing, I need to compare getWorldTime() with an hour (for example 18:29 and 20:22) and if the hour is between those times, then what ever xD
 
You can try this
LUA:
function compareCurrentTime(newSec,newMin,newHour,newDay,newMonth,newYear)  -- if not defined any of this then it default the current time value[ all arguments are optional]
	local cur = os.date("*t",os.time())
	newSec,newMin,newHour = newSec or cur.sec, newMin or cur.min, newHour or cur.hour
	newDay,newMonth,newYear = newDay or cur.day, newMonth or cur.month, newYear or cur.year
	cur.sec, cur.min , cur.hour, cur.day, cur.month, cur.year= newSec, newMin, newHour, newDay, newMonth, newYear
	return os.time() == os.time(cur)
end

example

LUA:
local hour, min, sec = 22, 6, 40
if compareCurrentTime(sec,min,hour) then
		doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"it is "..hour..":"..min..":"..secnod.." pm.")
	else
		doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"it is ".. os.date("%H:%M:%S",os.time()).." and you want "..hour..":"..min..":"..secnod.." pm.")
	end
 
Last edited:
Easier one :P
LUA:
Date_1 = {year=2011, month=01, day=20, hour=17, min=36, sec=20}
Date_2 = {year=2011, month=02, day=20, hour=17, min=36, sec=20}
Date_3 = {year=2011, month=03, day=20, hour=17, min=36, sec=20}

Stamp_1 = os.time(Date_1)
Stamp_2 = os.time(Date_2)
Stamp_3 = os.time(Date_3)


if Stamp_1 > Stamp_2 and Stamp_2 < Stamp_3 then
--do something if date_2 between date_1 and date_3
end

Original post > http://pastebin.com/mCm2vEaH
 
Back
Top