Date is wrong when converting paid Date in JavaScript

2
Hello, I have a .NET API that returns the data, the date comes in the format: 2016-06-17T00:00:00 and I try to convert it to date in JavaScript, so I do the following:

 var data = new Date(2016-06-17T00:00:00);

It works, but the date stays different on the variable, it always changes the day. What would I have to do for the conversion to occur normally?

It does not always happen, for example in the case below it occurs: API date: 2015-07-25T00: 00: 00

var data = new Date('2015-07-25T00:00:00');

The date is as follows: Fri Jul 24 2015 21:00:00 GMT-0300 (Brazil's official time), the day is changed.

Only the next example does not occur: API Data: 2016-06-24T09: 23: 53 After converting using the same code the date stays the same: Fri Jun 24 2016 06:23:53 GMT-0300 (Brazil official time)

    
asked by anonymous 24.06.2016 / 14:38

1 answer

1

Hello,

That's right, js considers that the string you are passing as a parameter is in UTC format (because it does not have the time zone in the string), so when converting to Date it considers your timezone, in case GMT-3 so it subtracts 3 hours from the string time.

One way to avoid this would be to have your API return the timezone in the string, something like this: '2015-07-25T00: 00: 00-0300'

    
24.06.2016 / 14:59