Skip to content Skip to sidebar Skip to footer

Parse Org.mozilla.javascript.nativedate In Java.util.date

I'm trying to parse a date that i get from JavaScript script evaluated with rhino library into java.util.Date, can i convert a org.mozilla.javascript.NativeDate into a java.util.Da

Solution 1:

In Rhino use

context.jsToJava(nativeDateObj, Date.class);

Solution 2:

Bvesco's answer works well. However doing this the other way round (java to js) is not entirely as simple - Context.javaTojs() does not work for dates. I eventually found the solution here - use the javascript constructor:

Object js = context.newObject(scope, "Date", newObject[] {date.getTime()});

The above post also mentioned the following alternative to convert a date from js to java (I haven't confirmed this):

Datedate = newDate((long) ScriptRuntime.toNumber(s)); 

Solution 3:

Have you tried;?

java.sql.Date.valueOf("date string");

Post a Comment for "Parse Org.mozilla.javascript.nativedate In Java.util.date"