ReactNativeで現在時刻表示
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
componentDidMount() {
}
componentWillUnmount() {
}
render() {
return (
<View style={styles.container}>
<Text h1>Hello, world!</Text>
<Text h2>It is {this.state.date.toLocaleTimeString()}.</Text>
</View>
);
}
}
export default class App extends React.Component {
render() {
return (
<Clock/>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});