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:

debounce = false

script.Parent.Touched:connect(function(onTouched)
if debounce == true then return end
debounce = true
msg = Instance.new("Message", game.Workspace)
msg.Text = os.date()
wait(2)
msg:Remove()
debounce = false
end)

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

local Months ={'January','February','March','April','May','June','July','August','September','October','November','December'}
local daysinmonth = {31,28,31,30,31,30,31,31,30,31,30,31}
local ctime = os.time()
local year = math.floor(ctime/60/60/24/365.25+1970)
local day = math.ceil(ctime/60/60/24%365.25)
for k, dim in pairs(daysinmonth) do
    if day > dim then
        day = day - dim
    else
        month = Months[k]
        break
    end
end 
if 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