If you don't want to use core function, you can use an old trick like this :
But I clearly think I will rewrite this function with the two ones Garkin just quoted.
Lua Code:
-- Return a formatted time
-- timeStr = GetTimeString()
-- formatStr: HH: hours (24), hh: hours (12), H: hour (24, no leading 0), h: hour (12, no leading 0), A: AM/PM, a: am/pm, m: minutes, s: seconds
local function createTimestamp(timeStr, formatStr)
formatStr = formatStr or pChat.opts.timestampFormat
-- split up default timestamp
local hours, minutes, seconds = timeStr:match("([^%:]+):([^%:]+):([^%:]+)")
local hoursNoLead = tonumber(hours) -- hours without leading zero
local hours12NoLead = (hoursNoLead - 1)%12 + 1
local hours12
if (hours12NoLead < 10) then
hours12 = "0" .. hours12NoLead
else
hours12 = hours12NoLead
end
local pUp = "AM"
local pLow = "am"
if (hoursNoLead >= 12) then
pUp = "PM"
pLow = "pm"
end
-- create new one
local timestamp = formatStr
timestamp = timestamp:gsub("HH", hours)
timestamp = timestamp:gsub("H", hoursNoLead)
timestamp = timestamp:gsub("hh", hours12)
timestamp = timestamp:gsub("h", hours12NoLead)
timestamp = timestamp:gsub("m", minutes)
timestamp = timestamp:gsub("s", seconds)
timestamp = timestamp:gsub("A", pUp)
timestamp = timestamp:gsub("a", pLow)
return timestamp
end