in React JS by
Q:

How to format date using React Intl?

1 Answer

0 votes
by

The injectIntl() higher-order component will give you access to the formatDate() method via the props in your component. The method is used internally by instances of FormattedDate and it returns the string representation of the formatted date.

import { injectIntl, intlShape } from 'react-intl'

const stringDate = this.props.intl.formatDate(date, {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric'
})

const MyComponent = ({intl}) => (
  <div>{`The formatted date is ${stringDate}`}</div>
)

MyComponent.propTypes = {
  intl: intlShape.isRequired
}

export default injectIntl(MyComponent)
Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Mar 3, 2020 in React JS by miceperry
+1 vote
asked Mar 2, 2020 in React JS by RShastri
0 votes
asked Mar 1, 2020 in React JS by RShastri
0 votes
asked Dec 8, 2020 in React JS by SakshiSharma
0 votes
0 votes
asked Mar 4, 2020 in React JS by JackTerrance
...