Page 1 of 1

new Date() returns wrong date

PostPosted: Mon Nov 29, 2010 2:03 pm
by maria
Hi All,

new Date() returns a date one hour later than current time.
I'm running my solution in Developer, both client and server on one machine.
The server page shows correct time on the server.
What's wrong?

Cheers,
Maria

Re: new Date() returns wrong date

PostPosted: Mon Nov 29, 2010 4:39 pm
by Andrei Costescu
Are you running the solution in web client or smart client?
What is the value of "servoy.use.client.timezone" property in servoy.properties?
How did you see the date value created with new Date()? In a field, via application.output(...) or some other way?
What version of Servoy are you running?

Re: new Date() returns wrong date

PostPosted: Tue Nov 30, 2010 12:24 am
by maria
Andrei Costescu wrote:Are you running the solution in web client or smart client?
What is the value of "servoy.use.client.timezone" property in servoy.properties?
How did you see the date value created with new Date()? In a field, via application.output(...) or some other way?
What version of Servoy are you running?


Ok...
1. I'm running the solution in web client.
2. 'servoy.use.client.timezone' is true. Not sure how this is going to work if webclient is 'sort of' running serverside.
3. The new Date() value comes up the same both via application.output() and via ctrl+shift+i during debugging.
4. It's Servoy version 5.1.4 -build 964. We're reluctant to upgrade it.

Cheers,
Maria

Re: new Date() returns wrong date

PostPosted: Tue Nov 30, 2010 10:57 am
by Andrei Costescu
Maybe the developer (that means both server and smart client under developer) is running in a different timezone.
Please check you smart client preferences to see if the default timezone that is set explains what is happening (that timezone will also be the timezone of the server under developer).

Re: new Date() returns wrong date

PostPosted: Wed Nov 14, 2012 12:26 pm
by imre_tokai
Hello,
Have this issue when running WebClient 5.2.15
new Date() gives the time on the server (what makes sense in basic theory as WebClient code is running server-side) but need there client's datetime as I configure certain time on the client and than when time matching on server action is triggered. Can do only if client & server are in same timezone (client's -user friendly).
servoy.use.client.timezone is true

WebClientUtils is suggested by Patrick in other thread, is that the optimal way to get client time zone's new Date()?
https://www.servoyforge.net/projects/webclientutils

Regards

Re: new Date() returns wrong date

PostPosted: Wed Nov 14, 2012 12:41 pm
by Andrei Costescu
So do you want the time as reported by the client's OS or the client's time computed based on client timezone and server time?

Re: new Date() returns wrong date

PostPosted: Wed Nov 14, 2012 3:06 pm
by imre_tokai
Thanks Andrei, good point

Option 2 (server time in client's timezone) has been built
-collecting offset on form's onShow() event
Code: Select all
var js = "var d = new Date();var offset = d.getTimezoneOffset();";
plugins.WebClientUtils.executeClientSideJS( js, globals.callbackOffset, ['offset'] );

-dividing collected offset with 60
-subtracting the hours from server hours
Code: Select all
date.setHours(date.getHours() - forms.frm_time_zone_sync_server_client.offset )


Let me know if this is completely generic and/or if anyone have better (optimal) work-flow, please

Regards

Re: new Date() returns wrong date

PostPosted: Thu Nov 15, 2012 10:09 am
by Andrei Costescu
You should get the same result from application.getTimestamp() since 6.0.8 (SVY-2726).
Before - in 5.x - it either simply returned a new Date() which isn't helpful for WC or in later versions it would not always be correct depending on the type of client and servoy.use.client.timezone.