title: .replace() not working. Giving error .replace is not a function
body: <p>I've written a javascript function to convert time in 12hrs format</p>
  
  <pre><code>function formatDate(nwdate) {
      var d = new Date(nwdate);
      var hh = d.getHours();
      var m = d.getMinutes();
      var s = d.getSeconds();
      var dd = "AM";
      var h = hh;
      if (h &gt;= 12) {
          h = hh-12;
          dd = "PM";
      }
      if (h == 0) {
          h = 12;
      }
      m = m&lt;10?"0"+m:m;
  
      s = s&lt;10?"0"+s:s;
  
  
      var pattern = new RegExp("0?"+hh+":"+m+":"+s);
  
      var replacement = h+":"+m;
      replacement += " "+dd;
      return nwdate.replace(pattern,replacement);
  }
  </code></pre>
  
  <p>It gives an error that .replace is not a function. Why is that ?</p>