
--字符串转时间戳 字符串格式:2019-12-24 15:53:23
function lxb.Common:getTimeStampByStirng(timeString)
if type(timeString) ~= 'string' then print("string2time: timeString is not a string") return 0 end
local fun = string.gmatch(timeString, "%d+")
local y = fun() or 0
if y == 0 then print("year == 0") return 0 end
local m = fun() or 0
if m == 0 then print("month == 0") return 0 end
local d = fun() or 0
if d == 0 then print("day == 0") return 0 end
local H = fun() or 0
if H == 0 then print("hour == 0") return 0 end
local M = fun() or 0
if M == 0 then print("minute == 0") return 0 end
local S = fun() or 0
if S == 0 then print("second == 0") return 0 end
return os.time( { year = y, month = m, day = d, hour = H, min = M, sec = S })
end
--转换到本地时间 字符串格式
function lxb.Common:getLocalTimeWithString(timeString)
local now = os.time()
local dif = os.difftime(now, os.time(os.date("!*t", now)))
local time = os.date("*t", self:getTimeStampByStirng(timeString) + dif);
local date = os.date("%Y-%m-%d %H:%M:%S", os.time(time));
return date;
end
--转换到本地时间 table格式
function lxb.Common:getLocalTimeWithTab(timeString)
local now = os.time()
local dif = os.difftime(now, os.time(os.date("!*t", now)))
local date = os.date("*t", self:getTimeStampByStirng(timeString) + dif);
return date;
end

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?