String for Date

6

I'm creating some parsers and was doing tests to develop Date.

This code:

value = '2015-12-31 23:16:00'
value = value.replace(/(\d{4}-\d{2}-\d{2}) ?(\d{2}:\d{2})?(:\d{2})?.*/, '$1T$2$3');
value = value.replace(/T$/, '');
value = value.replace(/(:\d{2})$/, '$1Z');

value = new Date(value)

runs correctly in Firefox, returning Date 2015-12-31T23:16:00.000Z , however in Chrome it displays Thu Dec 31 2015 21:16:00 GMT-0200 (BRST)

In addition to showing up differently, Chrome crashed two hours into the original time.

Would anyone know how I can rev it?

    
asked by anonymous 01.07.2015 / 20:07

1 answer

0

As @Guilherme Lautert said in the comment, in both cases returns the same value, only presenting it differently. What changes is only the time zone that was used, with GMT-0200 indicating two hours less than the current time on the Greenwich meridian. Example: link .

Try using

var horarioAtual = date.toLocaleTimeString();

to check. It is likely that it will return the correct value in both cases.

    
07.07.2015 / 17:05