Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { useState, useEffect } from "react";
import logo from "/logo.png";
import Clock from "./Clock";
import "./App.css";

function App() {
Expand All @@ -12,6 +14,12 @@ function App() {
<p>
Edit <code>src/App.jsx</code> and save to test HMR
</p>
<p>
<p>Timezone: Asia/Singapore</p>
<Clock timeZone="Asia/Singapore" />
<p>Timezone: Europe/London</p>
<Clock timeZone="Europe/London" />
</p>
</div>
</>
);
Expand Down
19 changes: 19 additions & 0 deletions src/Clock.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { useState, useEffect } from "react";

function Clock(props) {
const [date, setDate] = useState(new Date());

useEffect(() => {
const makeTimeGoUp = setInterval(handleDate, 1000);
return () => clearInterval(makeTimeGoUp);
}, []);

const handleDate = () => setDate(() => new Date());

return (
<>
<p>{date.toLocaleString("en-GB", { timeZone: props.timeZone })}</p>
</>
);
}
export default Clock;