To use moment.js
in react.
1) Install moment.js package npm install moment --save
2) Import moment
in your React component
import moment from 'moment'
Convert your timestamp (miliseconds) to date using new Date(1567485137)
and use fromNow
method of moment js.
moment(new Date(timestamp in milisecond).fromNow()
If you want to values as only days ago you can use from
method
moment(new Date(timestamp in milisecond)).from(new Date())
Using react-moment
If you are using react-moment
then use Moment
component as below:
import Moment from "react-moment";
then use as below
<Moment fromNow date={new Date(timestamp in milisecond).toJSON()} />