Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Incorrect date returned on server

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?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Incorrect date returned on server

Hello Aeneas,

Use simple Date object:

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

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Incorrect date returned on server

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Incorrect date returned on server

You can use UTC timezone in order to have no problems

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Incorrect date returned on server

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

Return to “Issues”