corona - Lua countdown timer for months and years -
below example of countdown timer corona sdk written in lua. how add days, months , years this?
local function updatetime() -- decrement number of seconds secondsleft = secondsleft - 1 -- time tracked in seconds. need convert minutes , seconds local minutes = math.floor( secondsleft / 60 ) local seconds = secondsleft % 60 -- make string using string format. local timedisplay = string.format( "%02d:%02d", minutes, seconds ) clocktext.text = timedisplay
end
days (and hours) trivial, months , years? since have no timestamp telling of how many seconds left what, it's hard knowing how many months, depending on length of months (28, 29, 30 or 31 days). same years if consider leap years well. in case, here's might sufficient:
local seconds_in_hour = 60 * 60 local seconds_in_day = 24 * seconds_in_hour local seconds_in_month = 30 * seconds_in_day -- assuming average of 30 days per month local seconds_in_year = 365 * seconds_in_day local years = math.floor((secondsleft / seconds_in_year) % 365) local months = math.floor((secondsleft / seconds_in_month) % 12) local days = math.floor((secondsleft / seconds_in_day) % 30) local hours = math.floor((secondsleft / seconds_in_hour) % 24) local minutes = math.floor((secondsleft / 60) % 60) local seconds = secondsleft % 60
Comments
Post a Comment