# Several small examples of lua time conversion

Time：2021-12-4

1. Convert the time seconds into the form of XX days, XX hours, XX minutes and XX seconds

Copy codeThe code is as follows:

–Convert the time seconds into the form of XX days, XX hours, XX minutes and XX seconds
function convertTimeForm(second)
local timeDay                   = math.floor(second/86400)
local timeHour                  = math.fmod(math.floor(second/3600), 24)
local timeMinute                = math.fmod(math.floor(second/60), 60)
local timeSecond                = math.fmod(second, 60)

return timeDay, timeHour, timeMinute, timeSecond
end

2. Convert the time seconds into the form of XX hours, XX minutes and XX seconds

Copy codeThe code is as follows:

local function formatTime(time)
local hour = math.floor(time/3600);
local minute = math.fmod(math.floor(time/60), 60)
local second = math.fmod(time, 60)
local rtTime = string.format(“%s:%s:%s”, hour, minute, second)

return rtTime
end

3、

Copy codeThe code is as follows:

–Convert the seconds from January 1, 1990 to mm / DD / yyyy and mm / DD / yyyy
–Endtime in milliseconds
os.date(“%Y-%m-%d  %H:%M”,math.floor(endTime/1000))

## Hive built-in function summary

1. Related help operation functions View built-in functions: Show functions; Display function details: desc function ABS; Display function extension information: desc function extended concat; 2. Learn the ultimate mental method of built-in function Step 1: carefully read all the functions of the show functions command to establish an overall understanding and impression Step 2: use […]