Search code examples
javascriptjavastrptimegraalvm

Javascript strptime() is adding one month extra


From an Spring boot project we are calling GraalVM for processing some rules written in JavaScript. The GraalVM version is 'org.graalvm.sdk=1.0.0-rc11'. When we are using strptime(), it's adding one month extra. Like for the date 24/02/2021, it is converted to 24/03/2021. Can you please let me know why this is happening?

Here source is passed as the source date like 24/02/2021

const return_date = new Date().strptime(source, format(source)).toIsoString()

NOTE: This is happening if we execute this on the last day of a month like on 31st January, other day it is giving me the expected date returned. So any idea why strptime() is behaving like this?


Solution

  • other than strptime() function, You can directly use this way:

    const return_date = new Date(source).toISOString()