How to Format a Date in JavaScript: Complete Guide with Examples

How to Format a Date in JavaScript: Complete Guide with Examples

To format a date use the following code – 

<script type=”text/javascript”>
var options = { weekday: ‘long’, year: ‘numeric’, month: ‘long’, day: ‘numeric’ };
var today = new Date();

console.log(today.toLocaleDateString(“en-US”)); // 9/17/2016
console.log(today.toLocaleDateString(“en-US”, options)); // Saturday, September 17, 2016
console.log(today.toLocaleDateString(“hi-IN”, options)); // शनिवार, 17 सितंबर 2016

</script>

Al Mahbub Khan
Written by Al Mahbub Khan Full-Stack Developer & Adobe Certified Magento Developer

Full-stack developer at Scylla Technologies (USA), working remotely from Bangladesh. Adobe Certified Magento Developer.