Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

date function formatting in jquery

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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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/
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maqskywalker
maqskywalker

ASKER

thanks