JavaScript to Convert Date to MM/DD/YYYY Format
In this post, you'll find a quick, 7-line code block of JavaScript that you can use to covert dates to the MM/DD/YYYY format.
Join the DZone community and get the full member experience.
Join For Freefunction GetFormattedDate() {
var todayTime = new Date();
var month = format(todayTime .getMonth() + 1);
var day = format(todayTime .getDate());
var year = format(todayTime .getFullYear());
return month + "/" + day + "/" + year;
}
Some other great DZone articles to learn JavaScript:
- How JavaScript Actually Works, Part 1
- Node.js Tutorial for Beginners (Part 1): Intro to Node and Express
- An Introduction to JavaScript/ES6 Arrow Functions
JavaScript
Convert (command)
Opinions expressed by DZone contributors are their own.
Comments