Reputation: 61
I need to get time in "00:00:00" type. I have field to do this, but if I get 00 in last place I have "02:02". I try to use time.lenght, and I want to add missing number, buti it is dosn't work...
<input id="preparation_time" defaultValue = "00:00:00" type="time" step="1" className={styles.input} onChange={e => this.order.preparation_time = e.target.value}/>
and I have in console when I click submit only "02:02: not "02:02:00:
async submit(){
this.setState({error : false});
this.setState({response : false});
console.log(this.order.preparation_time);
(..)
If I enter seconds, they are but if I enter zero, they disappear and I don't know how to add these zeros. I can't get the length.
Sory I wrote lenght, no length. But if whos want to know why is no second. Answer is below.
Upvotes: 0
Views: 220
Reputation: 1054
Different browsers have different implementation for time type. Chrome skips/ doesn't consider seconds value if its 0 seconds. Mean while firefox considers complete time which has been provided.
If you need to maintain consistency you could add the seconds when you see that length of the time value is less than 8.
if(e.target.value.length < 8) {
this.order.preparation_time = e.target.value + ":00"
}
Upvotes: 1