title: Nashorn NativeDate conversion to java.util.Date
body: <p>When returning Javascript <code>Date</code> objects to Java with Nashorn on Java 8 like so:</p>
  <pre><code>ScriptEngineManager factory = new ScriptEngineManager();
  ScriptEngine engine = factory.getEngineByName(&quot;nashorn&quot;);
  Object js = engine.eval(&quot;new Date();&quot;);
  </code></pre>
  <p>With the following attempts I get exceptions:</p>
  <ol>
  <li><p><strong><code>Date javaDate = (Date)js;</code></strong></p>
  <p><code>jdk.nashorn.api.scripting.ScriptObjectMirror cannot be cast to java.util.Date</code></p>
  </li>
  <li><p><strong><code>Date javaDate = js.to(Date.class);</code></strong></p>
  <p><code>Cannot cast jdk.nashorn.internal.objects.NativeDate to java.util.Date</code></p>
  </li>
  <li><p><strong><code>Date javaDate = (Date)ScriptUtils.convert(js.to(NativeDate.class), Date.class);</code></strong></p>
  <p><code>Cannot cast jdk.nashorn.internal.objects.NativeDate to java.util.Date</code></p>
  </li>
  </ol>
  <p>Back with Rhino I was simply using <code>context.jsToJava(nativeDateObj, Date.class);</code>.</p>
  <p>Any ideas how I can actually cast this NativeDate when it's returned to Java?</p>
  <p>P.S. If I do js.toString() then it gives me &quot;[Date 2012-01-01T19:00:00.000Z]&quot;. I guess I could regex parse that ... but why-oh-why ...</p>