How do I convert tick() to a date/time format?

For example, tick() just returns the number of seconds passed since whatever day it is in 1970.
Currently, it just displays it in integer format.

How can I make it so it displays with this format:
dd/mm/yy or using DateTime library i’m not quite sure?

Looked at this wiki page for this os Documentation. Specifically the os.date function.

print(os.date("*t"))
--[[
The table printed:
{
   ["day"] = 24,
   ["hour"] = 7,
   ["isdst"] = false,
   ["min"] = 29,
   ["month"] = 2,
   ["sec"] = 18,
   ["wday"] = 4,
   ["yday"] = 55,
   ["year"] = 2021
}
--]]

That’s os.date, not tick(). They return different values.

The difference between them is that os.time uses UTC , while tick() uses the current timezone. (tick() on the client returns time relative to the machine’s time zone while on the server it returns time relative to the server’s time zone), tick exposes miliseconds while os.time does not.

tick returns the current server time in “Unix Time Format”. It is not proper Unix time. It’s a very large number, and this number is affected by timezones as servers in ROBLOX are misconfigured and return the wrong time , based on the timezone that they are in.

It’s recommended to use os for stuff like that.
You want to get date with tick? Here you go.

local data = os.date("*t", tick()); --// check article for more info
print(data.day, data.month, data.year)

image

2 Likes
local r=os.date("*t")
print(("%02d/%02d/%02d"):format(r.day, r.month,r.year-2000))

If you wanted a faster but less readable version:

print(os.date("%x"))

Just pass an extra argument if you wanted to specify time. (In this case tick())

local function getCurrentTimeFormat(seconds)
	local currentTime = os.date("!*t")
	if seconds then
		currentTime = os.date("*t", seconds)
	end
	
	local hour = currentTime.hour
	local minute = currentTime.min
	local second = currentTime.sec
	
	local day = currentTime.day
	local month = currentTime.month
	local year = currentTime.year
	
	if hour < 10 then
		hour = 0 .. hour
	end
	if minute < 10 then
		minute = 0 .. minute
	end
	if second < 10 then
		second = 0 .. second
	end
	if day < 10 then
		day = 0 .. day
	end
	if month < 10 then
		month = 0 .. month
	end
	if year < 10 then
		year = 0 .. year
	end
	
	return ("%s:%s:%s, %s/%s/%s"):format(hour, minute, second, month, day, year)
end

Easier format, you can play around it if you wish.

Is this solved? If it is shouldn’t it have a solution marked already?