date-formatter-test-ecsion
Version:
25 lines (19 loc) • 556 B
JSX
import dayjs from 'dayjs';
import React from 'react';
const DateFormatter = ({ formatter = 'YYYY-MM-DD' }) => {
const now = dayjs();
// Define the date variable
let date;
// Format the date based on the formatter prop
if (formatter === 'YYYY-MM-DD' || formatter === 'MMMM D, YYYY') {
date = now.format(formatter);
} else {
date = now.format(); // Default format
}
return (
<>
<p>Today's Date: {date}</p>
</>
);
}
export default DateFormatter;