Simple Clock code

No replies
willsingleton
User offline. Last seen 13 weeks 6 days ago. Offline
Joined: 3 Sep 2009

-- clock code

local holdClock = os.time();
local time = display.newText("12:12:12:am",40,410,nil,37);
time:setTextColor(30,015,255,255);

local function timer ( event )
local myTime = os.time()
if ( holdTime ~= myTime ) then
holdTime = myTime;
local t = os.date("*t");
local ampm = "am";

if (t.hour == 12) then
ampm = "pm";
end
if (t.hour < 12) then
ampm = "am";
end
if (t.hour > 12) then
t.hour = t.hour - 12;
ampm = "pm";
end
if (t.hour == 0) then
t.hour = 12;
ampm = "am"
end

local s = string.format("%2d:%02d:%02d%s",t.hour,t.min,t.sec,ampm);
print(s);
time.text = s;
end
end
local function main ()
Runtime:addEventListener("enterFrame",timer);
end
main();