import React, { useState, useEffect } from 'react';
// AnalogClock component to render a single clock
const AnalogClock = ({ time, title }) => {
const getHandRotations = (date) => {
const seconds = date.getSeconds();
const minutes = date.getMinutes();
const hours = date.getHours();
const secondsDeg = (seconds / 60) * 360;
const minutesDeg = (minutes / 60) * 360 + (seconds / 60) * 6;
const hoursDeg = (hours / 12) * 360 + (minutes / 60) * 30;
return { secondsDeg, minutesDeg, hoursDeg };
};
const { secondsDeg, minutesDeg, hoursDeg } = getHandRotations(time);
return (
{title}
);
};
// Main LiveClock component to manage time state
const LiveClock = () => {
const [now, setNow] = useState(new Date());
useEffect(() => {
const intervalId = setInterval(() => {
setNow(new Date());
}, 1000); // Update every second
return () => clearInterval(intervalId); // Cleanup interval on component unmount
}, []);
// Create a date object for UTC time
const utcDate = new Date(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCSeconds(),
);
return (
);
};
export default LiveClock;