以下倒计时时钟的工作时间为秒,分钟,天,月,年,我将如何为此添加毫秒?
local secondsLeft = 3.154e + 7
-- one year
local clockText = display.newText("00.00:00:00:00", display.contentCenterX, 80, "font1.ttf", 60)
sceneGroup:insert(bg)
sceneGroup:insert(title)
sceneGroup:insert(summary)
sceneGroup:insert(clockText)
sceneGroup:insert(clockText)
local SECONDS_IN_HOUR = 60 * 60
local SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR
local SECONDS_IN_MONTH = 30 * SECONDS_IN_DAY
-- assuming an average of 30 days per month
local SECONDS_IN_YEAR = 365 * SECONDS_IN_DAY
local function updateTime()
-- decrement the number of seconds
secondsLeft = secondsLeft - 1
-- time is tracked in seconds. We need to convert it to minutes and seconds
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
-- make it a string using string format.
local timeDisplay = string.format("%02d·%02d·%02d·%02d·%02d·%02d", years, months, days, hours, minutes, seconds)
clockText.text = timeDisplay
end
local countDownTimer = timer.performWithDelay(100, updateTime, secondsLeft)
答案 0 :(得分:0)
这是一个例子,对你有用:
setup:upgrade