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

How to convert human time into Unix time?

Hi, so I know from the os.time page in the API reference that you can quite easily get a human date from a unix time, like this:

local stringToFormat = "Today is %x, which is a %A, and the time is %X."
local timestamp = 906000490
local result = os.date(stringToFormat, timestamp)

So that's good because you can easily turn back-end system time into something a user can read, but how do I do it the other way around, so that a user can input a time and date, and it be converted into unix time to be easily stored and maths easily done to it? Thanks!

1 answer

✓ Accepted answer

You simple convert days, hours etc into seconds and add it up. i.e

local days = dayinput * 86400 --seconds in a day
local hours = hourinput * 3600 --seconds in an hour
local minutes = mininput * 60 --seconds in a minute
local seconds = secinput

local unixtime = tonumber(days + hours + minutes + seconds)

Of course, you would need the year and month for full accuracy but it's something and something to prevent incorrect inputs.

1 comment

0

Oh I didn't even think of that, thank you!

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