Categories
interview

Format currency and date manually in Javascript

Format Currency

In case you want to implement a function to format currency instead of just using toLocaleString() then, you can use the following.

Output

$123,121,000.00

Demo

Format Date

const formatDate = (date) => {
  const d = new Date(date);
  return `${d.getMonth() + 1}/${d.getDate()}/${d.getFullYear()}`;
};
 
console.log(formatDate('2018-03-01T10:00:00Z'));

Output

Demo