Simple Date and Time Functional Components

Mindwatering Incorporated

Author: Tripp W Black

Created: 05/01 at 12:18 AM

 

Category:
NodeJS
Reference

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

×