0

In short this function returns a time which is then used to query a JSON file, it seems for the query to work my date needs to be in string format, It will not work if I pass the result of recent_time() into the query.

function recent_time(process) {
    date_array = []

    for (var object in process) {
        var processtime = new Date(process[object]);
        date_array.push(processtime)
    }

    max_date = new Date(Math.max.apply(null, date_array));
    return max_date
}

Currently the value returned is in the format 2019-05-22T11:01:18.000Z I need it to read as this (for my json query purpose):

"2019-05-22T11:01:18.000Z" - note it is in string format

I have tried return max_date.toString() However this returns the format

Wed May 22 2019 11:01:18 GMT+0100 (British Summer Time)

Any help is appreciated

EcSync
  • 842
  • 1
  • 6
  • 20
  • 1
    Use `max_date.toISOString()` – Anurag Srivastava May 22 '19 at 10:04
  • Did you try consulting the [documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Conversion_getter) to see if a suitable function existed (or whether you could create such a format from the functions available)? – ADyson May 22 '19 at 10:04
  • Possible duplicate of [How do I output an ISO 8601 formatted string in JavaScript?](https://stackoverflow.com/questions/2573521/how-do-i-output-an-iso-8601-formatted-string-in-javascript) – ADyson May 22 '19 at 10:05

1 Answers1

1

You are probably looking for the .toISOString() method.

Anurag Srivastava
  • 14,077
  • 4
  • 33
  • 43