Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Print the date and time?

Asked by 10 years ago

How do you print the date/time in ROBLOX Lua? The code I tried was:

01debounce = false
02 
03script.Parent.Touched:connect(function(onTouched)
04if debounce == true then return end
05debounce = true
06msg = Instance.new("Message", game.Workspace)
07msg.Text = os.date()
08wait(2)
09msg:Remove()
10debounce = false
11end)

It did not seem to work. Is it even possible to display the date/time in Roblox Lua?

1 answer

Log in to vote
3
Answered by 10 years ago

Roblox does not have os.date() so to get the date you could try this

01local Months ={'January','February','March','April','May','June','July','August','September','October','November','December'}
02local daysinmonth = {31,28,31,30,31,30,31,31,30,31,30,31}
03local ctime = os.time()
04local year = math.floor(ctime/60/60/24/365.25+1970)
05local day = math.ceil(ctime/60/60/24%365.25)
06for k, dim in pairs(daysinmonth) do
07    if day > dim then
08        day = day - dim
09    else
10        month = Months[k]
11        break
12    end
13end
14if day < 10 then day = '0' .. tostring(day);end

So for exampleprint(day .. ' ' .. month .. ' ' .. year) would be 13 August 2014

0
bruh this post was 4 years ago LOL greatneil80 2647 — 5y
0
@greatneil80 lmao now it has. Igoralexeymarengobr 365 — 5y
Ad

Answer this question