Reputation: 5809
I have a string date coming from a server and wanted to see if there was a way to get a JS date object from it.
Example: format mm/yy
exDate = "0919"
I want to return a new date object with the last day of the month also added to it. So for example the above would return
Mon Sep 30 2019 00:00:00 GMT-0500 (EST)
Is the above possible with just a 2 digit year and returning the last day in the month with the date object?
Upvotes: 1
Views: 53
Reputation: 106620
Parse in the string to a date object specifying the month ahead and 0
for the date:
var t = new Date("20" + exDate.substring(2, 4), exDate.substring(0, 2), 0);
Upvotes: 3