I can get the Date function directly using moment.js but when the minutes are under 10 it will not display the 0.
Please see picture below for example.

the time is meant to be 12:02 and 12:03
constructor(props) {
super(props);
this.state = {
datetimefinish: '',
};
}
componentDidMount() {
var that = this;
var date = new Date().getDate('0' + Number()); //Current Date
var month = new Date().getMonth() + 1; //Current Month
var year = new Date().getFullYear(); //Current Year
var hours = new Date().getHours(); //Current Hours
var min = new Date().getMinutes(); //Current Minutes
var sec = new Date().getSeconds(); //Current Seconds
that.setState({
//Setting the value of the date time
datetimefinish:
hours + ':' + min
});
}
<Text style={styles.text}>{this.state.datetimefinish}</Text>
Please try this if using moment.js to get the Date Time
componentDidMount() {
var that = this;
var date = moment()
.format(' HH:mm');
that.setState({ datetime: date });}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With