title: DateTimeFormatter for Javascript Date.toString output
body: <p>Trying to support Javascript's <code>new Date().toString()</code> output format with Java's <code>DateTimeFormatter</code> but can't seem to make it work.</p>
  
  <p>Js output is of the following nature:</p>
  
  <ul>
  <li>Wed Apr 04 2018 09:56:16 GMT-0500 (SA Pacific Standard Time)</li>
  <li>Wed Apr 04 2018 16:12:41 GMT+0200 (CEST)</li>
  </ul>
  
  <p>My current formatter:</p>
  
  <pre><code>int defaultOffset = ZonedDateTime.now().getOffset().getTotalSeconds();
  DateTimeFormatter dtfJs =  new DateTimeFormatterBuilder()
                                  .appendPattern("EE MMM dd yyyy HH:mm:ss [OOOO (zzzz)]")
                                  .parseDefaulting(ChronoField.OFFSET_SECONDS,defaultOffset 
                                  .toFormatter();
  </code></pre>
  
  <p>If i <code>.parse()</code> those date strings from js, I get the following error:</p>
  
  <blockquote>
    <p>[date] could not be parse at index 25</p>
  </blockquote>
  
  <p>Index 25 for both the dates mentioned is:</p>
  
  <ul>
  <li>GMT-0500 (SA Pacific Standard Time)</li>
  <li>GMT+0200 (CEST)</li>
  </ul>
  
  <p>I know the problem is with the <strong>:</strong> (colon) because if I print the current date with <code>dtfJs</code>, I get:</p>
  
  <blockquote>
    <p>Wed Apr 04 2018 10:25:10 GMT-05:00 (Colombia Time)</p>
  </blockquote>
  
  <p>So the part of the <code>GMT-05:00</code> is exected as <code>GMT-0500</code> in the string recieved but I can't find a <a href="https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html" rel="nofollow noreferrer">reserved pattern letter</a> which matches this.</p>
  
  <p>The docs say:</p>
  
  <blockquote>
    <p>Offset O: This formats the localized offset based on the number of
    pattern letters. One letter outputs the short form of the localized
    offset, which is localized offset text, such as 'GMT', with hour
    without leading zero, optional 2-digit minute and second if non-zero,
    and colon, for example 'GMT+8'. Four letters outputs the full form,
    which is localized offset text, such as 'GMT, with 2-digit hour and
    minute field, optional second field if non-zero, and colon, for
    example 'GMT+08:00'. Any other count of letters throws
    IllegalArgumentException.</p>
    
    <p>Offset Z: This formats the offset based on the number of pattern
    letters. One, two or three letters outputs</p>
    
    <p>the hour and minute, without a colon, such as '+0130'. The output will
    be '+0000' when the offset is zero. Four letters outputs the full form
    of localized offset, equivalent to four letters of Offset-O. The
    output will be the corresponding localized offset text if the offset
    is zero. Five letters outputs the hour, minute, with optional second
    if non-zero, with colon. It outputs 'Z' if the offset is zero. Six or
    more letters throws IllegalArgumentException.</p>
  </blockquote>
  
  <p>Which means that the four letter will output always with colon ":", thus throwing <code>DateTimeParseException</code> </p>
  
  <p>Help greatly appreciated, thanks</p>
  
  <h1>Edit</h1>
  
  <p>Thanks to @mszymborski I managed to pass on to validate the parenthesis part "(CEST)", what would be useful here ?</p>
  
  <p>I tried with  <code>EE MMM dd yyyy HH:mm:ss 'GMT'Z (zz)</code> but this only works with the second date in the list, not the first</p>
  
  <ul>
  <li>GMT-0500 (SA Pacific Standard Time) ERROR</li>
  <li>GMT+0200 (CEST)  PASS</li>
  </ul>