-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
79 lines (64 loc) · 1.57 KB
/
App.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React,{useState, useEffect} from 'react';
import {
StyleSheet,
Text,
View,
Platform
} from 'react-native';
const App = () =>{
const [currentDay,setCurrentDay]=useState(null);
const [currentTime,setCurrenTime]=useState(null);
const weekDay =['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const getCurrentDate= () =>{
let hour = new Date().getHours();
let minutes = new Date().getMinutes();
let second = new Date().getSeconds();
let am_pm = 'AM';
if ( hour < 10 )
hour ='0'+hour
if ( minutes < 10)
minutes='0'+minutes
if ( second < 10 )
second='0'+second
if ( new Date().getHours > 12 )
am_pm='PM'
setCurrenTime( hour + ':' + minutes + ':' + second + ' ' + am_pm );
weekDay.map( ( item, key) => {
if (key == new Date().getDay())
{
setCurrentDay(item);
}
})
}
useEffect( () => {
const Interal=setInterval( () => {getCurrentDate()},1000);
return () => {
clearInterval(Interal)
}
})
return(
<View style={container}>
<Text style={day}>{currentDay}</Text>
<Text style={time}>{currentTime}</Text>
</View>
)
}
const styles = StyleSheet.create({
container:{
flex: 1,
backgroundColor: '#383838',
justifyContent: 'center',
alignItems: 'center',
paddingTop: (Platform.OS == 'ios')? 20 : 0
},
day: {
fontSize: 50,
color: '#e59400',
},
time: {
fontSize: 50,
color: '#e59400',
}
});
const {container, day, time} = styles;
export default App;