Change locale in react-datepicker

后端 未结 6 1230
一向
一向 2021-02-04 03:30

I am using react-datepicker NPM package,
I tried to follow documentation but I was unable to import

registerLocale 

and

         


        
6条回答
  •  半阙折子戏
    2021-02-04 03:46

    import React, { Component } from 'react';
    import DatePicker, { registerLocale } from "react-datepicker";
    import "react-datepicker/dist/react-datepicker.css";
    import ja from "date-fns/locale/ja";
    
    registerLocale("ja", ja);
    
    class App extends Component {
      constructor(props) {
        super(props);
        this.state = {
          date: new Date()
        }
        this.handleChange = this.handleChange.bind(this);
      }
    
      handleChange(date) {
        this.setState({
          date
        });
      }
    
      render() {
        return (
          
    ); } } export default App;

    I could get the result you wanted. And I tried to make it with moment library but it didn't work on my code. sorry

提交回复
热议问题