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

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

Asked by 6 years ago

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

Log in to vote
1
Answered by 6 years ago

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.

0
but you can get the player's location irl CjayPlyz 643 — 6y
0
isn't that depricated now? MMCraftin 8 — 6y
Ad
Log in to vote
1
Answered by
Sulfone 141
6 years ago
Edited 6 years ago

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

Answer this question