I would love to use os.date() on ROBLOX, so that we can create calendars and automatic systems that will work by date
We can also do time stamps on date this way.
Example :
A ModuleScript that will make the entire game ready for Christmas
A Shop that will have daily dails
A Shop that will have âsummerâ deals, when it is truely summer.
months = {"January","February","March","April","May","June","July","August","September","October","November","December"}
daysinmonth = {31,28,31,30,31,30,31,31,30,31,30,31}
function getDate()
time = os.time()
local year = math.floor(time/60/60/24/365.25+1970)
local day = math.ceil(time/60/60/24%365.25)
local month
for i=1, #daysinmonth do
if day > daysinmonth[i] then
day = day - daysinmonth[i]
else
month = i
break
end
end
return month, day, year
end
local month, day, year = getDate()
root.CompletedTasks.CurrentDate.Text = "Today's Date is: "..month.."/"..day.."/"..year
Straight off of free models â readily available to all.
@Echo.
The math behind it isnât really accurate. Leap years for example arenât done in that code
And I really donât understand why we have os.time() and os.difftime() and not os.date()
Is there an easily-accessible API that you can read the month/day/year from somewhere out there (using HTTPService)? Anyone who could take that and make it into a script would be a hero!
It wonât be accurate since time is taken for the HTTP request to reach both ends.[/quote]When youâre just trying to get it down to the DAY, I donât think it matters that much.
Could just grab it off of this site[/quote]Any clue how? Iâm a total noob to HTTPService, soâŚ
I would rather have some TimeToDate function that takes a unix time argument and returns a tuple of the date values (seconds, minutes, hours, etc.). This way we can get the date of arbitrary times.
Ahahahahahaha XD[/quote]
Thatâs not a helpful post at all. Making fun of people for asking legitimate questions isnât okay IMO.
It wonât be accurate since time is taken for the HTTP request to reach both ends.[/quote]When youâre just trying to get it down to the DAY, I donât think it matters that much.
Could just grab it off of this site[/quote]Any clue how? Iâm a total noob to HTTPService, soâŚ[/quote]
Here, I made something simple. It takes two arguments: Timezone and Pattern.
Use this to construct patterns based on PHPâs date()
Good timing! My timestamp() function stopped working recently (badly coded, but lasted 2 years), so I started writing a new one. Little did I know it would take me 5 hours. Christ. I have no idea, I was much better when I was 15. If itâs ever taking you that long to do something, stop, take a break and rethink. I wasted too much time.
EDIT: Forgot to mention, IT SUPPORTS LEAP YEARRRSSSSS!!
But here it is: (sorry if itâs hard to read I have a blue theme to âkeep meâ cool, I hate the Summer heat.)
And the code, change the timezone to your liking. I live in EST.
function getMonth(DoTy, months)
local var2 = DoTy
for i = 1, #months do
if var2 <= months[i] then return i, var2 else var2 = var2 - months[i] end
end
end
function timestamp()
local months = {31, 28, 31, 30, 31, 30, 31,31,30, 31, 30, 31}
local timezone, offset_hours = "EST", -4
local secondspassed = os.time()+(3600*offset_hours)
local yearspassed = math.floor(secondspassed/31557600)
local YoTc = yearspassed-30 -- Year of the Century (change the 30 to 130 when it's 2100 :D (if it's 2100....))
local DoTy = math.floor((secondspassed-(yearspassed*(31557600)))/86400)+1
if YoTc/4-math.floor(YoTc/4) == 0 then months[2] = 29 end
local MoTy, DoTm = getMonth(DoTy, months)
local HR = math.floor((secondspassed-((math.floor(secondspassed/86400))*86400))/3600)
local MIN = math.floor((secondspassed-((math.floor(secondspassed/3600))*3600))/60)
local SEC = math.floor((secondspassed-((math.floor(secondspassed/60))*60)))
if string.len(HR)==1 then HR = "0"..HR end
if string.len(MIN)==1 then MIN = "0"..MIN end
if string.len(SEC)==1 then SEC = "0"..SEC end
return MoTy.."/"..DoTm.."/"..YoTc..", "..HR..":"..MIN..":"..SEC.." "..timezone..", Day of the Year: "..DoTy
end