Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I parse a date in text form in Roblox Lua?

Asked by 7 years ago

I have a datestring like this: "12/12/2016 7:23:17 PM"

How can I convert it to something useful without rewriting a bunch of date logic?

All I actually care about is getting the rough number of seconds of time from that date until now.

I guess I can just hack it, ignoring leap years, etc, but I was hoping there would be something better.

0
Probably is some way, which I dont know. I suggest trying to find an online API which might do it? User#13152 0 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
function date2ostime(dateStr)
    --12/12/2016 7:23:17 PM
    local res = {}
    for mm in dateStr:gmatch("(%d+)") do
        table.insert(res,mm)
        print(mm)
    end
    return os.time{year=res[3], month=res[1], day=res[2], hour=res[4], min=res[5], sec=res[6]}
end
Ad

Answer this question