Based on the discussion converting string representation of unknown date-format to Date in java, I want to use the JavaScript Date
function in my App-Engine project. However, ScriptEngine does not work on App-Engine. So I need a little help converting to Rhino. Here is the ScriptEngine code I need to convert:
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine engine = scriptEngineManager.getEngineByName("JavaScript");
String script = "var date = new Date('" + dateInUnknownFormat + "'); var timestamp = date.getTime();";
engine.eval(script);
long timestamp = ((Double) engine.get("timestamp")).longValue();
The following has not worked
private static long parseDateUsingRhino(String dateInUnknownFormat){
Context mozillaJsContext = Context.enter();
Scriptable scope = mozillaJsContext.initStandardObjects();
String script = "var date = new Date('" + dateInUnknownFormat + "'); var timestamp = date.getTime();";
Object obj = mozillaJsContext.evaluateString( scope, script, "TestScript", 1, null );
Double timeDouble = Double.parseDouble((String) obj);
long timestamp = timeDouble.longValue();
return timestamp;
}
and I have already replaced "TestScript"
with null
and ""
.