[Solved] How to extract a string from a line of characters? [closed]


Use the string.prototype.match method:

var str = "/Date(1396505647431)/";
  1. str.match(/Date\(\d+\)/)[0] gives "Date(1396505647431)"

  2. var time = new Date(+str.match(/\d+/)[0]) gives Thu Apr 03 2014 11:44:07 GMT+0530 (India Standard Time)

  3. time.toLocaleTimeString() gives "11:44:07 AM"

DEMO

solved How to extract a string from a line of characters? [closed]