title: Convert PHP DateTime format to Moment.js
body: <p>I am writing a javascript prototype for a string that will accept a PHP DateTime Format and convert it to a Moment.js DateTime Format. However, I am having a problem building the final string. I basically have it working, but I don't know how to keep the normal symbols. The problem with my code is I basically split the string by any non-alpha character. This means when I rebuild the conversion it does not include the other character. I am not sure how to fix that problem. My code is below</p>
  
  <pre><code>String.prototype.toMoment = function() {
      var items = this.split(/[^A-Za-z]/);
      var returnItem = "";
      var conversions = {
          'd': 'DD',
          'D': 'ddd',
          'j': 'D',
          'l': 'dddd',
          'N': 'E',
          'S': 'o',
          'w': 'e',
          'z': 'DDD',
          'W': 'W',
          'F': 'MMMM',
          'm': 'MM',
          'M': 'MMM',
          'n': 'M',
          't': '',
          'L': '',
          'o': 'YYYY',
          'Y': 'YYYY',
          'y': 'YY',
          'a': 'a',
          'A': 'A',
          'B': '',
          'g': 'h',
          'G': 'H',
          'h': 'hh',
          'H': 'HH',
          'i': 'mm',
          's': 'ss',
          'u': 'SSS',
          'e': 'zz',
          'I': '',
          'O': '',
          'P': '',
          'T': '',
          'Z': '',
          'c': '',
          'r': '',
          'U': 'X',
      };
  
      for (var item in items) {
          returnItem += conversions[items[item]];
      }
  
      return returnItem;
  }
  </code></pre>
  
  <p>for example if I use the follow code <code>moment().format('m/d/Y H:i:s'.toMoment())</code> it does work and converts the returns string to <code>MMDDYYYYHHmmss</code>. The problem is I need it to return <code>MM/DD/YYYY HH:mm:ss</code>. Any help would be appreciated, Thanks!</p>