FerbZides
(FerbZides)
September 13, 2020, 11:07am
#1
i have made code similar to this topic:
not sure about tick(), but you can use the following:
local gmtTime = os.date("!*t", os.time())
print("Time: " .. gmtTime.hour .. ":" .. gmtTime.min.. ":" .. gmtTime.sec)
os.date is explained on roblox’s website here
without any arguments, it returns the current date and time
you can see what the table contains in the link i sent you.
first parameter "!*t" gets the time in utc / gmt (theyre the same time) as a table
you can see what the table contains in the link i sent you.
second para…
but i want to get current time like mine like GMT+8 not GMT+0
and know if it is PM or AM
current code
-- // services \\ --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Shared = ReplicatedStorage.Shared
local SecondsToTime = require(Shared.SecondsToTime)
-- // objects \\ --
local TimeText = script.Parent.CurrentTime
-- // events \\ --
RunService.RenderStepped:Connect(function()
local GMT = os.date("!*t", os.time())
TimeText.Text = GMT.hour..":" ..GMT.min
end)
1 Like
FerbZides
(FerbZides)
September 13, 2020, 11:15am
#3
not all players in roblox have the same time and i dont only want GMT+8 i want every player’s time to be correct
Example:
if their time is GMT+7 and it shows GMT+8 then it’d be 7 pm for their time in their phone or pc but in the game it is 8 pm
if 11:59 am is done then 12:00 pm is pm its basically a 12 hour time not 24 hour time
royaltoe
(royaltoe)
September 13, 2020, 11:47am
#4
How’s this?
local function formatTime(use12Hour, t )
local t = t or tick()
local hours = math.floor(t / 3600) % 24
local mins = math.floor(t / 60) % 60
local secs = t % 60
local isPm = hours > 12
local amOrPm = isPm and "pm" or "am"
--convert to 12 hour time if we want to use 12 hour time instead of 24:
if use12Hour then
hours = isPm and hours - 12 or hours
return string.format("%d:%02d:%02d"..amOrPm, hours, mins, secs)
else
return string.format("%d:%02d:%02d ", hours, mins, secs)
end
end
print(formatTime(true))
6 Likes
FerbZides
(FerbZides)
September 13, 2020, 11:51am
#5
good actually i want to know of what it prints
1 Like
23brewert
(23brewert)
March 15, 2021, 6:25pm
#6
How would I change the timezone to EST?