Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Print the date and time?

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

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

2 comments

0

bruh this post was 4 years ago LOL

0

@greatneil80 lmao now it has.

This discussion is preserved as it was. New answers, comments, and votes are closed.