How to make a clock in british time?

  1. What do you want to achieve?
    I want to achieve a clock like the image attached, in british time with hours, minutes, and seconds.
    image

  2. What is the issue?
    I cannot figure it out, and how it works however everything I’ve tried wont work on a Surface-Gui.

  3. What solutions have you tried so far?
    I looked around, but nobody has known.

1 Like

We can’t help you if you don’t give us enough information. What do you need help with, making the gui, scripting, or what?
Do you want to get the time from game.Lightning.TimeOfDay?

No. real life time as stated… Please read before doing anything. I need help with the scripting.

1 Like

I’ve made a topic that talks about making a clock based on a specific timezone. Try this code out:

local function MilitaryToStandard(hour)
	return if hour > 12 then hour - 12 else hour, if hour > 12 then true else false
end

local function ConvertTo2Digit(digit)
	return if #tostring(digit) < 2 then 0 .. digit else digit
end

local date = os.date("!*t", os.time() + 3600) -- since british time is UTC+1, we add an hour to os.time() in seconds
local min = ConvertTo2Digit(date.min)
local hour, isPM = MilitaryToStandard(date.hour)
local result = hour .. ":" .. min .. if isPM then " PM" else " AM"

warn(result)

Would it be going in a local script or a normal script, and would it format like this?
image

1 Like

Here’s some updated code that returns the format you want (you can put this code anywhere).

local function MilitaryToStandard(hour)
	return if hour > 12 then hour - 12 else hour, if hour > 12 then true else false
end

local function ConvertTo2Digit(digit)
	return if #tostring(digit) < 2 then 0 .. digit else digit
end

local date = os.date("!*t", os.time() + 3600) -- since british time is UTC+1, we add an hour to os.time() in seconds
local min = ConvertTo2Digit(date.min)
local hour, isPM = MilitaryToStandard(date.hour)
local result = hour .. ":" .. min .. ":" .. date.sec

warn(result)

image
It doesnt want to work in our local script on a surface gui.

1 Like

I tried the code and it works perfectly fine in a local script.

image

Could you show your clock code?

Sure.

You have to actually print the ‘result’ variable for it to pop up on console-

local function MilitaryToStandard(hour)
	return if hour > 12 then hour - 12 else hour, if hour > 12 then true else false
end

local function ConvertTo2Digit(digit)
	return if #tostring(digit) < 2 then 0 .. digit else digit
end

local date = os.date("!*t", os.time() + 3600) -- since british time is UTC+1, we add an hour to os.time() in seconds
local min = ConvertTo2Digit(date.min)
local hour, isPM = MilitaryToStandard(date.hour)
local result = hour .. ":" .. min .. ":" .. date.sec

print(result) -- you forgot this

image
and here is the explorer

we put the print(result) at the end and it doesnt seem to work

1 Like

Okay, try this code:

This should actually change the text on your GUI.

local text = script.Parent

local function MilitaryToStandard(hour)
	return if hour > 12 then hour - 12 else hour, if hour > 12 then true else false
end

local function ConvertTo2Digit(digit)
	return if #tostring(digit) < 2 then 0 .. digit else digit
end

while true do
	local date = os.date("!*t", os.time() + 3600) -- since british time is UTC+1, we add an hour to os.time() in seconds
	local min = ConvertTo2Digit(date.min)
	local hour, isPM = MilitaryToStandard(date.hour)
	local result = hour .. ":" .. min .. ":" .. date.sec
	
	text.Text = tostring(result)
	warn(text.Text)
	task.wait(1)
end

Thank you! It works finally, took a while but we got there.