// __tests__/helpers.test.js
const { format_date, format_plural } = require('../utils/helpers');
test('format_date() returns a date string', () => {
const date = new Date('2020-03-20 16:12:03');
expect(format_date(date)).toBe('3/20/2020');
});
========================
// /utils/helpers.js
module.exports = {
format_date: (date) => {
return `${new Date(date).getMonth() + 1}/${new Date(date).getDate()}/${new Date(date).getFullYear()}`;
},
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter