How do you print the date/time in ROBLOX Lua? The code I tried was:
01 | debounce = false |
02 |
03 | script.Parent.Touched:connect( function (onTouched) |
04 | if debounce = = true then return end |
05 | debounce = true |
06 | msg = Instance.new( "Message" , game.Workspace) |
07 | msg.Text = os.date() |
08 | wait( 2 ) |
09 | msg:Remove() |
10 | debounce = false |
11 | end ) |
It did not seem to work. Is it even possible to display the date/time in Roblox Lua?
Roblox does not have os.date() so to get the date you could try this
01 | local Months = { 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' } |
02 | local daysinmonth = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } |
03 | local ctime = os.time() |
04 | local year = math.floor(ctime/ 60 / 60 / 24 / 365.25 + 1970 ) |
05 | local day = math.ceil(ctime/ 60 / 60 / 24 % 365.25 ) |
06 | for 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 |
13 | end |
14 | if day < 10 then day = '0' .. tostring (day); end |
So for exampleprint(day .. ' ' .. month .. ' ' .. year)
would be 13 August 2014