title: Strip Time Zone from a string using JavaScripty, Moment.js, etc?
body: <p>Suppose I have a string like "01/22/2014 2:07:00 PM -08:00".</p>
  
  <p>I want to</p>
  
  <ul>
  <li>a) Format it in ISO 8601 with time offsets from UTC <a href="http://goo.gl/JTfAZq" rel="noreferrer">http://goo.gl/JTfAZq</a>, so it becomes "2014-01-22T14:07:00-08:00"</li>
  <li>b) Strip out time offset part so it becomes "01/22/2014 2:07:00 PM" [and then format it in ISO 8601 so it becomes "2014-01-22T14:07:00"]</li>
  </ul>
  
  <p>Sure I can use JavaScript string functions (and regular expressions), but it seems to be a better approach to use JavaScript Date() object facilities or Moment.js. Neither work, however. Both automatically convert dates to a current system timezone (-05:00 for me), so 2:07 PM becomes 5:07 PM. I found two ways of doing that "strip out time offset then format" task, but both looks ugly and brittle:</p>
  
  <pre><code>var mydateTime = "01/22/2014 2:07:00 PM -08:00";
  
  // strip out time offset part using substring() so that Moment.js
  // would think time is specified in a current zone
  var myNewDateTime1 = moment(mydateTime.substring(0, mydateTime.length - 7)).format("YYYY-MM-DDTHH:mm:ss")
  
  // or probably even worse trick - strip out time offset part using format
  var myNewDateTime2 = moment(mydateTime, "MM/DD/YYYY h:mm:ss A").format("YYYY-MM-DDTHH:mm:ss")
  </code></pre>
  
  <p>I understand that JavaScript Date() object is not designed to preserve a time zone, but doesn't more elegant and stable solution exist for a) and b) ?</p>