Navigation

1/27/2016

Parsing string for date using Javascript


Have a CMD command that returns the user expiration date, to get it into Javascript:



var stringToParse = "You have a doctor's appointment on 2012/03/13 16:00.  Please show up on time.";
var dateString    = stringToParse.match(/\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}/);
var dt            = new Date(dateString);
console.log(dt);        //prints "Tue March 13 16:00:00 EDT 2012"



http://www.htmlgoodies.com/html5/javascript/date-parsing-using-javascript-and-regular-expressions.htm

No comments:

Post a Comment