Reputation: 23
I am trying to format date time string value using react-moment in my react component. moment returns an object but i need a string value from moment. This is the code I have:
import Moment from 'react-moment';
const dateToFormat = '2015-08-31T16:14:00.000Z';
const datetm = <Moment format="dddd, MMMM Do YYYY, h:mm a" date = {dateToFormat} />;
datetm
always return object but I want it to be string. Does moment has any attribute that can be set to get string value instead an object?
Upvotes: 1
Views: 1854
Reputation: 846
You are using react-moment which is a wrapper component for the moment js. You can you use this as a react component. but not as normal use. Instead use moment js.
install the moment js package using npm.
> npm install --save moment
in your js file
> import moment from 'moment';
then use moment instance.
> moment(<date string>/<date object>/<moment object>).format(<format string>)
Upvotes: 3