-1

I have a value that shows as Sat Apr 28 2018 00:00:00 GMT-0600 (MDT) but I want to convert it to just 4/28/2018. and when I do value.toISOString(); it gives me back 2018-04-26T06:00:00.000Z, how do i take off the end part?

yabna
  • 99
  • 3
  • 13

1 Answers1

1

You can do something like this

var d = new Date(); // Your date object
console.log(dateString = getDateString(d));

function getDateString(date) {
    return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getYear();
    // Or
    return (date.getMonth() + 1) + '-' + date.getDate() + '-' + date.getYear();
}
Zohaib Ijaz
  • 21,926
  • 7
  • 38
  • 60
  • This is clearly a duplicate, you need `date.getMonth() + 1` and the year should use *getFullYear*. – RobG Apr 23 '18 at 21:54