How to format a date object?

How to format a date object?

const td = new Date();

const result = td.getDate() + "/" + (td.getMonth()) + "/" + td.getFullYear();

Or

const result = new Intl.DateTimeFormat('en-US').format(td);

Or

if we need complex or quick solutions of date format then MomentJS is a good option.

import moment js

const result = moment().format('YYYY-MM-DD HH:m:s');

Comments

Popular posts from this blog

world tourism guide Template

Es6 how to check if value is not null or undefined?