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
jQuery

Avatar of undefined
Last Comment
maqskywalker

8/22/2022 - Mon
leakim971

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
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
maqskywalker

ASKER
thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck