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?
Asked
Active
Viewed 267 times
-1
-
...and? Have you tried _anything_? – Luca Kiebel Apr 23 '18 at 19:48
-
whoops figured out it was a problem with my redux – yabna Apr 23 '18 at 20:07
1 Answers
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