Link to home
Create AccountLog 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
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of maqskywalker
maqskywalker

ASKER

thanks