ama
ama

Reputation: 51

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

Upvotes: 1

Views: 12414

Answers (1)

Tholle
Tholle

Reputation: 112787

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

E.g. 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>
    );
  }
}

Upvotes: 2

Related Questions