date function formatting in jquery

maqskywalker
maqskywalker used Ask the Experts™
on
Inside my jquery button click event i have this date variable

var d = new Date();

But when I display the value inside variable d the format looks like this:

Fri Sep 07 2018 15:35:50 GMT-0700 (Pacific Daylight Time)


How do i format it to this format:  MM/DD/YYYY
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
var d = new Date();
var d2 = function(n) { return n>9?n:"0"+n; };
var strDate = d2(1+d.getMonth()) + "/" + d2(d.getDate()) + "/" + d.getFullYear();

Open in new window


if you need more power on formatting date, you may use a lib like this one : https://momentjs.com/
Multitechnician
Top Expert 2014
Commented:
testing

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial