-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.jsx
50 lines (31 loc) · 910 Bytes
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React,{useState,useEffect} from 'react'
function PractiseReact(){
const [time,setTime] = useState(new Date())
useEffect(() => {
const interValidId = setInterval(() =>{
setTime(new Date())
},1000)
return () =>{
clearInterval(interValidId)
}
},[])
function formatTime(){
let hours = time.getHours()
const minutes = time.getMinutes()
const seconds = time.getSeconds()
const meridieam = hours >= 12 ? "PM":"AM"
hours = hours % 12 || 12
return `${padZero(hours)}:${padZero(minutes)}: ${padZero(seconds)}: ${meridieam}`
}
function padZero(number){
return (number < 10? "0": "") + number
}
return(
<div>
<div>
<h2><span>{formatTime()}</span></h2>
</div>
</div>
)
}
export default PractiseReact