I've been trying to make a Log thingy using data store and to sort everything out i want to find out if there are any inbuilt functions like this one. If you know please tell me so i dont have to struggle making my own one.
✓ ANSWER ACCEPTED
Are there any inbuilt roblox functions that return the current date/month/year?
1 answer
✓ Accepted answer
Not Quite.
os.time will return the seconds passed since the Unix Epoch according to UTC time, and you may use this to log the times that things happen. If you need something which can parse the time for you, we have one in Valkyrie
local SECOND = 1;
local MINUTE = 60*SECOND;
local HOUR = 60*MINUTE;
local DAY = 24*HOUR;
local WEEK = 7*DAY;
local YEAR = 365*DAY;
local LYEAR = 366*DAY;
local AYEAR = 365.25*DAY;
local TYEAR = 365.24*DAY;
local MONTH = TYEAR/12;
local iMONTH = DAY/0.0328549;
local ce, fl, t = math.ceil, math.floor, os.time
local Days = {
"Monday";
"Tuesday";
"Wednesday";
"Thursday";
"Friday";
"Saturday";
"Sunday"
}
local Months = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
}
local iMonths = {
"January";
"Febuary";
"March";
"April";
"May";
"June";
"July";
"August";
"September";
"October";
"November";
}
local function isLeapYear(year)
if year0 == 0 then
return year%400==0;
end;
return year%4==0;
end
local function TimeFromSeconds(sec)
sec = sec or t();
sec = sec%DAY
return string.format("%.2d:%.2d:%.2d", sec/HOUR, sec/60%60, sec%MINUTE)
end
local function DayFromSeconds(sec) -- Epoch was on a Thursday
sec = sec or t();
return Days[ce(((sec+3*DAY)%WEEK)/DAY)]
end
local function GetMonth(sec) -- Not so lazy months
sec = fl(sec or t());
sec = sec+1; -- Otherwise it treats midnight as being yesterday
local ileap = isLeapYear(fl(sec/YEAR)+1970);
while sec > (ileap and LYEAR or YEAR) do
sec = sec - (ileap and LYEAR or YEAR)
ileap = isLeapYear(fl(sec/YEAR)+1970);
end;
local days = ce(sec/DAY)
local month = 0;
local useLeapFeb = isLeapYear(fl(sec/YEAR+1970))
for i,v in pairs(Months) do
if i==2 and useLeapFeb then v=29 end;
if days>v then
days = days-v;
else
month = iMonths[i]
break
end
end
return month, days;
end
local function FullDate(sec)
sec = sec or t();
local ret = {}
ret.Time = TimeFromSeconds(sec)
ret.Month, ret.Date = GetMonth(sec)
ret.Day = DayFromSeconds(sec)
ret.Year = fl(sec/YEAR)+1970
ret.Second = sec%MINUTE
ret.Minute = fl(sec/60%60)
ret.Hour = fl(sec%DAY/HOUR)
return ret;
end
-- FullDate is now the one you want
print(FullDate().Month) --> June
3 comments
0
You seem to be a day out test "1466248319" output Date 17 should be 18?
0
Yeah it's probably because I don't account for that 0 seconds is the 1st. Probably. Otherwise, using TYEAR might solve that instead of AYEAR.
0
I already made it myself in a much more simple script because of the giant wait time, but thanks anyways, i'll accept it for your work
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
This is the one I made but it takes the long approach, https://www.roblox.com/time-module-item?id=428330572