Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS date filter in React

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?

like image 745
Abdelrahman Abdelhafez Avatar asked Feb 11 '17 14:02

Abdelrahman Abdelhafez


People also ask

Which filter is used to convert an input string to date format in Angular?

AngularJS date filter is used to convert a date into a specified format. When the date format is not specified, the default date format is 'MMM d, yyyy'.

How do you add a date filter in HTML?

change', function (e) { var value = $("#myInput"). val(); var firstDate = moment(value, "DD/MM/YYYY"). day(0). format("DD/MM/YYYY"); $("#myInput").


1 Answers

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

like image 123
Shubham Khatri Avatar answered Oct 21 '22 11:10

Shubham Khatri