function sTime() t = tick() local sec = math.floor((t%60)) local min = math.floor((t/60)%60) local hour = math.floor(math.fmod((t/3600),24)) print(hour) if not (sec<10) then sec = math.floor(sec) else sec = "0"..math.floor(sec) end ssec = sec mmin = tostring((min < 10 and "0" or "") .. min) tag = (Type == 1 and (hour < 12 and "AM" or "PM") or "") mhour = math.fmod(hour,12)--[[((Type == 1 and hour < 10 and "0" or "") .. tostring(Type == 0 and (hour == 0 and 12 or hour > 12 and (hour-12) or hour) or hour)) -- Ternary operators FTW. Helps get rid of 'if then' stuff. Actually learned this off of Java programming: z = (x == y ? "Yes" : "No")]] local c,s = ":",(Type == 1 and " " or "") -- Colon, (space if 12 hr clock) Time = (mhour .. c .. mmin .. (ssec and c .. sec or "") .. s .. tag) return Time end
Right now, it's printing something like 11:11:12, and it doesn't show AM or PM. This isn't something I made, I'm just using it to get the time, and the coding is a bit hard for me to understand it completely. So does anyone know how I could change this to make it show up with an AM or PM tag?
Thank you!
function sTime() t = tick() local sec = math.floor((t%60)) local min = math.floor((t/60)%60) local hour = math.floor(math.fmod((t/3600),24)) print(hour) if not (sec<10) then sec = math.floor(sec) else sec = "0"..math.floor(sec) end ssec = sec mmin = tostring((min < 10 and "0" or "") .. min) tag = (Type == 1 and (hour < 12 and "AM" or "PM") or "") mhour = math.fmod(hour,12)--[[((Type == 1 and hour < 10 and "0" or "") .. tostring(Type == 0 and (hour == 0 and 12 or hour > 12 and (hour-12) or hour) or hour)) -- Ternary operators FTW. Helps get rid of 'if then' stuff. Actually learned this off of Java programming: z = (x == y ? "Yes" : "No")]] local c,s = ":",(Type == 1 and " " or "") -- Colon, (space if 12 hr clock) Time = (mhour .. c .. mmin .. (ssec and c .. sec or "") .. s .. tag) if hour < 12 then return "AM" else return "PM" end end print(sTime())
There, it is checking the hour which is already an int.