local time = os.time()
function TimeToDate(time, beginIdx, endIdx, showZero)
if type(time) == "number" then
local link_str = ""
local time_info = os.date("*t", time)
time_info = {time_info.year, time_info.month, time_info.day, time_info.hour, time_info.min, time_info.sec}
local beginIdx = beginIdx or 1
local endIdx = endIdx or #time_info
local time_desc_info = {"年", "月", "日", "时", "分", "秒"}
for i,v in ipairs(time_info) do
if i >= beginIdx and i <= endIdx then
local time_str = tostring(v)
if showZero and v < 10 then
time_str = "0"..time_str
end
link_str = link_str..time_str..time_desc_info[i]
end
end
return link_str
end
return " "
end
local time_str = TimeToDate(time, nil, nil, true)
print(time_str)
lua-时间转日期
最新推荐文章于 2023-01-10 16:19:12 发布