简体   繁体   中英

Reactjs : display time in 24hr format

I am trying to print time in 24hour format using react js. And I have used the below example,which gives 12 hour format. Any ideas to get 24 hr format?

https://www.npmjs.com/package/react-time-picker

Thanks in Advance

You can use a locale prop that uses the 24 hour format instead of the am/pm format.

Eg Sweden sv-sv uses the 24 hour format.

Example ( CodeSandbox )

class App extends Component {
  state = {
    time: "10:00"
  };

  onChange = time => this.setState({ time });

  render() {
    return (
      <div style={{ marginTop: "200px" }}>
        <TimePicker
          onChange={this.onChange}
          value={this.state.time}
          locale="sv-sv"
        />
      </div>
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM