Is possible to convert os.date/time into a UNIX date?

One of my first posts, was fixing a script that starts an event in a defined date. A month later i made a post about doing a countdown for it, the best answer was using UNIX time with a special code, I feel that searching for an UNIX time is kinda hard than using os.date/time. So, my question is: there’s a way to convert os.date/time into a UNIX date? Thanks for reading :+1:

2 Likes

What do you mean by a UNIX date? Do you mean a time in the format MMDDYYYY or something like that?

UNIX time, if I remember, it was the seconds lapsed since 1th January 1970. os.date/time returns a table with years, days, months, etc.

Alright so you did mean UNIX time, I wasn’t sure about whether you meant that or something else. I believe os.time returns the number of seconds after the epoch.

1 Like

I found that you can return UNIX time with os, but how do I convert normal os.date/time to UNIX?

I’m still a bit confused on what you mean by “to UNIX”. What would you like the outcome to be? Like what would it look like? os.date and os.time are not the same thing

os.time actually returns the UNIX time, why do you want to convert the time formatted as in os.date to UNIX time?

He is wondering if he could find the UNIX time when he puts in a certain MM/DD/YY HH:MM:SS combination.

Oh well you could just reference elements from the os.date dictionary and concatenate them.

I think he is trying to make a countdown timer similar to what was used in the Bloxys by using the date and time for when the countdown should end.

Converting from UNIX to time dictionary can be achieved by os.date(“!*t”, unixTime)

From time dictionary to UNIX: os.time(dictionary)

Example:

local t1 = os.date("!*t")
print(os.time(t1)) -- 1587861366
print(os.time()) -- 1587861366

local t2 = os.date("!*t")
t2.year = 1970
print(os.time(t2)) -- 9938212

local t3 = os.date("!*t", 10)
print(os.time(t3)) -- 10

Maybe this thread will help to understand what it is that you’re after and whether the solution and code snippets there apply:

1 Like

Unfortunately the version of Lua Roblox uses does not support those format specifiers, or intentionally were removed :frowning:

I got a question:

How do i get the UNIX time of a defined date? For example:

June 1st 2020.

Thanks for reading.

1 Like

I meant to get the UNIX date from a defined date, the user who I’m replying gave me a script that converts os.date to UNIX time, but im kinda confused on how it works.

Make a dictionary containing time information and then use os.time like in my previous post

local t = {
    year = 2020,
    month = 6,
    day = 1
}

local unixTime = os.time(t)
1 Like

Will this work if I fill out the other values os.date normally returns like min, hour and sec?
Also is there a way to input a timezone?

Yes you can input minutes, hours and seconds too, but you can’t input the timezone.

However depending on what you’re trying to achieve you can calculate the difference between timezones in seconds and add to that unixTime variable.

1 Like