Page 1 of 1

Incorrect date returned on server

Posted: Tue Apr 14, 2015 11:31 pm
by Aeneas McBurney

When I pass this date string "2015-04-31" to a server script and get date with this function

function stringToDate(s) {
s = s.split(/[-: ]/);
return new Date(s[0], s[1]-1, s[2],0, 0, 0);
}

The date returned is the next day being 2015-05-1.

Why is this happening?


Incorrect date returned on server

Posted: Wed Apr 15, 2015 8:09 am
by Serhii Kulibaba

Hello Aeneas,

Use simple Date object:

var s = "2015-04-31";
var d = new Date(s);


Incorrect date returned on server

Posted: Wed Apr 15, 2015 8:12 am
by Aeneas McBurney

I have already done this but same result. I think it's something to do with timezones as I'm in New Zealand and it changes depending on time of day.


Incorrect date returned on server

Posted: Fri Apr 17, 2015 5:59 pm
by Serhii Kulibaba

You can use UTC timezone in order to have no problems


Incorrect date returned on server

Posted: Fri Apr 17, 2015 6:40 pm
by Aeneas McBurney

Yes I would like to know how to return correct date from server code to my timezone


Incorrect date returned on server

Posted: Sat Apr 18, 2015 1:01 pm
by Serhii Kulibaba