Error converting to ISOString in javascript

1

I'm trying to pass a date to the ISODate format using the javascript toISOString () method, the problem is that it's a bad time for me.

var fecha_hora = '2017-05-15 15:39:22'
var f = new Date(fecha_hora);
var fechaISO = f.toISOString();
console.log('fecha_hora:' + fecha_hora + '\nfecha_ISO:'+fechaISO);

prints the following string:

'fecha_hora:2017-05-15 15:39:22
fecha_ISO:2017-05-15T20:39:22.000Z'
    
asked by Alberto Rojas 13.07.2017 в 19:23
source

1 answer

2

Your problem is that you need to add the UTC , if you do not place it updates it with the time difference that is the client's browser with respect to UTC

  

UTC stands for Coordinated Universal Time (UTC) in Spanish time   universal coordinated wiki

The example below:

var fecha_hora = '2017-05-15 15:39:22 UTC'
var f = new Date(fecha_hora);
var fechaISO = f.toISOString();
console.log('fecha_hora: ' + fecha_hora + '\n fecha_ISO: '+fechaISO);
    
answered by 13.07.2017 / 19:52
source