Karate Framework – Why Javascript function returns an array with NaN values?

Just keep it simple and use Java please. There are examples in the doc: https://github.com/intuit/karate#java-interop

If it is too troubling, write JS utility functions.

* def toDate =
    """
    function(s) {
      var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
      var sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
      return sdf.parse(s)           
    }
    """ 
* def raw = "2018-10-19T11:53:39.8795965Z"
* def date = toDate(raw)
* print date.day, date.month, date.year

Just look at the API for java.util.Date and you have all of that now.

Leave a Comment