0

I'm wondering how I can parse this date string in object.modified in JavaScript into date format. If I have this code:

var object = {
    "path" : "C:/Users/exampleuser/Desktop/test/testfile.txt",
    "modified" : "24-10-2019"
};

I've tried using Date.parse() but no luck so far.

Dale K
  • 25,246
  • 15
  • 42
  • 71

2 Answers2

-1
var object = {
    "path" : "C:/Users/exampleuser/Desktop/test/testfile.txt",
    "modified" : "24-10-2019"
};

var objectParse = Date(object.modified)

console.log(objectParse)
Baruch_Mashasha
  • 197
  • 1
  • 3
  • 13
  • `new Date("24-10-2019")` produces an invalid date in Safari, Chrome and Firefox at least. See [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – RobG Oct 24 '19 at 10:29
-1

You can create a date object and pass the value of object.modified in that

var object = {
    "path" : "C:/Users/exampleuser/Desktop/test/testfile.txt",
    "modified" : "24-10-2019"
};
var date = Date(object.modified)
console.log(date)

Output will be : Thu Oct 24 2019 14:29:46 GMT+0530 (India Standard Time)

grayskull
  • 11
  • 1
  • `new Date("24-10-2019")` produces an invalid date in Safari, Chrome and Firefox at least. See [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – RobG Oct 24 '19 at 10:29