Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

1 comment

0

Probably is some way, which I dont know. I suggest trying to find an online API which might do it?

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.