Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Graalvm js interprets java.util.Date in different way than it did by nashorn js

We have migrated from jdk8 to jdk17, and had to use graalvm js instead of nashorn js. We found, that graalvm js interprets java.util.Date as long not as a Date. Here are 2 examples.

Using jdk8 (nashorn):


    public static void main(String[] args) {
        
            Map<String, Object> parameters = new HashMap<>();
            Date activationDate = DATE_FORMAT.parse("04/30/2008 00:00:00");
            parameters.put("aActivationDate", activationDate);
            
            
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("JavaScript");
            
            Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
            bindings.putAll(parameters);
            
            engine.eval("print(aActivationDate)", bindings);
        }

The result of this code is: Wed Apr 30 00:00:00 EDT 2008

Using jdk17 with graalvm js.

    public static void main(String[] args) {
        
        Map<String, Object> parameters = new HashMap<>();
        Date activationDate = DATE_FORMAT.parse("04/30/2008 00:00:00");
        parameters.put("aActivationDate", activationDate);
                
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        
        Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
        bindings.put("polyglot.js.nashorn-compat", true);
        bindings.putAll(parameters);
        
        engine.eval("print(aActivationDate)", bindings);
    }

The result of this code is: 1209528000000

What should be done so, that graalvm interprets java.util.Date in the same way as nashorn js? Thank you.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!