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

How can I get the current time and date in real life?

I've browsed through the Roblox wiki and I couldn't find anything that could help me. Is there any way I can get the current time and date from a server using HTTPService? Or maybe using the OS?

2 answers

You can put something in serverscriptservice called time and put this inside of it.

local TimeServer = "http://www.timeapi.org/utc/now?%25Q"
local CurrentTime = tonumber(Game:GetService("HttpService"):GetAsync(TimeServer, true))
local ServerTime = tick()

return function() return (CurrentTime / 1000) - ServerTime + tick() end

Then you could use it in a script like this.

local getTime = require(Game.ServerScriptService.Time)

print(getTime())
wait(1)
print(getTime())

This uses the utc time zone, because roblox servers are run in different zones I used time api. If you are just trying to get how long it has been that will be fine but you can't get a player's current timezone.

2 comments

0

but you can get the player's location irl

0

isn't that depricated now?

The os.date function is useful for this. It can return a date table for either UTC time or local time.

Example usage:

local date_table = os.date("!*t") -- this is for UTC time, "*t" would be for local time
print(date_table.month) --> 5
print(date_table.day) --> 26

More information, including what fields a date table has, can be found at: http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#os.date https://www.lua.org/pil/22.1.html

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