-
Notifications
You must be signed in to change notification settings - Fork 0
Usable Code
VihaanGitHub edited this page Jul 1, 2025
·
4 revisions
Alright, This is the main code of the Clock API that you can copy.
First, to use the days, You need this array:
const days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];And if you've got that array, this is the Get Day code:
const todayIndex = new Date().getDay(); // Gets today's day from 0-6
const currentDayName = days[(todayIndex + 6) % 7]; // Shifts the days from 0-6 to 1-7 to match our
// array, and links the array so we get the day.Let's move on to the Get Time Code (Accurate Version)
setInterval(() => {
const now = new Date();
const hour = now.getHours();
}, 1000);Use:
now.toLocaleTimeString();In your code to get the time in 00:00:00 format, such as:
document.getElementById("showtime").innerText = "The Time is " + now.toLocaleTimeString();Tip: Put this inside the setInterval 👆
And the const hour can be used like this example:
if (hour >= 12) {
document.getElementById("TimeText").innerText = "It's after 12 O' clock!";
}Here is how to get the date:
const today = new Date();
const date = today.toLocaleDateString();And finally, Here is how to get the timezone:
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;