Task:
Create a functional component that displays current date, time, or day of week.
datetoday.js
const today = new Date();
function formatTime(date) {
return new Intl.DateTimeFormat(
'en-US',
{ hour: 'numeric', minute: 'numeric', second: 'numeric' }
).format(date);
}
export default function DateToday() {
return (
<h1>Today is: { formatTime(today) }</h1>
);
}
dayofweek.js
const today = new Date();
function formatDate(date) {
return new Intl.DateTimeFormat(
'en-US',
{ weekday: 'long' }
).format(date);
}
export default function DayOfWeek() {
return (
<h1>{ formatDate(today) }</h1>
);
}
datetoday.js
const today = new Date();
function formatDate(date) {
return new Intl.DateTimeFormat(
'en-US',
{ year: 'numeric', month: 'numeric', day: 'numeric' }
).format(date);
}
export default function DateToday() {
return (
<h1>Today is: { formatDate(today) }</h1>
);
}
previous page
|