I have a date like the following:
2016-04-13T09:57:21-04
I am trying to cast this to a javascript date:
event.timestamp = new Date(event.timestamp);
where event.timestamp is a string representation of the date. The problem is that this is set as converted to undefined. I am almost certain that my datetime is a valid ISO format. What am I doing wrong here?
Edit
Some have noted that the datetime is not valid, and I agree that javascript does not consider it so, but I generate the datetime from a Scala API call
using jodatime:
DateTime.now()
So this will generate a valid datetime (at least for scala). The -04 is the offset. I am not arguing that the date time is or is not valid in Javascript, because that is obvious. I am curious if there is a way to make it valid for javascript, because the jodatime date library seems pretty standard in Java and Scala and I am assuming there is a way to make it work with JavaScript.
Edit 2 Thriggle's answer is correct, but you cal also use Moment to get the date in a correct format:
moment(event.timestamp, "YYYY-MM-DD HH:mm Z").toDate();
moment can read a datetime in the format I have (2016-04-13T09:57:21-04)