AngularJS date filter in React
Asked Answered
I

1

5

In AngularJS, one could display datetime strings in various formats using date filters:

<p>Date: {{ "2017-02-10T12:10:00.000Z" | date : "fullDate" }}</p>

and that would render:

Date: Friday, February 10, 2017

Is there such a thing as a date filter in React?

Ilanailangilang answered 11/2, 2017 at 14:21 Comment(0)
B
8

You can make use of npm package moment to achieve what you want.

Install it like:

npm install --save moment

And then import in your React component like:

import moment from 'moment';

You can use it like:

const date = new Date();
const formattedDate = moment(date).format('DD-MMM-YY HH:mm:ss');

Docs

Board answered 11/2, 2017 at 14:40 Comment(3)
great answer, herePavement
is there any default filter in reactjs for the same ?Gader
@PardeepJain, no there isn't a default filter for itBoard

© 2022 - 2024 — McMap. All rights reserved.