Page 1 of 1

Real Web Client datetime and timezone

PostPosted: Fri Nov 12, 2010 1:51 pm
by rossent
Hi all,

Is there a way to get the "real client" datetime (and timezone) in the Web Client - by "real client" I mean the actual client machine where the browser is running and not the Servoy web client instance running on the application server.

The Servoy application.getTimeStamp() when used in a web client returns the datetime of the application server and not the actual user datetime.

Thanks for your help!

Re: Real Web Client datetime and timezone

PostPosted: Sat Nov 13, 2010 11:40 pm
by jcarlos
I've never done this, but I suppose that you'll need to capture the client's time zone and then perform a conversion. Check Servoy Developer application node to see is there is something that will help you to capture the client's time zone.

JC

(Posted from my PDA)   

Re: Real Web Client datetime and timezone

PostPosted: Sun Nov 14, 2010 4:56 am
by ptalbot
You need the date to be evaluated on the client side (in the browser), you can do that using the Web Client Utils plugin.

You will find it on ServoyForge of course:
https://www.servoyforge.net/projects/webclientutils/files

Put the jar in your /application_server/plugins folder.

Then do something like this:
Code: Select all
function onAction(event) {
   var js = "var d = new Date().toUTCString();";
   plugins.WebClientUtils.executeClientSideJS(js, callbackMethod, ['d']);
}

function callbackMethod(d) {
   var date = new Date(d);
        // now do anything you want with this date.
   application.output(date);
}

Re: Real Web Client datetime and timezone

PostPosted: Sun Nov 14, 2010 1:16 pm
by Harjo
great tip Patrick, thanks!

Re: Real Web Client datetime and timezone

PostPosted: Thu Nov 18, 2010 11:40 am
by Andrei Costescu
In 6.0 application.getTimeStamp() for WC will simulate client date/time based on server date/time and client timezone.
But if you need the "real" time of the client machine that is the way to go, yes. (Web Client Utils plugin)

Re: Real Web Client datetime and timezone

PostPosted: Thu Jan 13, 2011 3:55 pm
by Westy
function onAction(event) {
var js = "var d = new Date().toUTCString();";
plugins.WebClientUtils.executeClientSideJS(js, callbackMethod, ['d']);
}

function callbackMethod(d) {
var date = new Date(d);
// now do anything you want with this date.
application.output(date);
}


Can this be done in Servoy 3.5?

Dean Westover

Re: Real Web Client datetime and timezone

PostPosted: Thu Jan 13, 2011 4:12 pm
by ptalbot
Best way to know is to try it! ;)

Re: Real Web Client datetime and timezone

PostPosted: Thu Jan 13, 2011 4:27 pm
by Westy
I did. It did not work. That's why I asked. :)

Dean

Re: Real Web Client datetime and timezone

PostPosted: Thu Jan 13, 2011 4:44 pm
by ptalbot
I suppose the API is too old although it doesn't look like it.
What kind of error do you have in the log?

Re: Real Web Client datetime and timezone

PostPosted: Thu Jan 13, 2011 5:48 pm
by Westy
"Function keyword found in this script" when click verify button in method editor.

Dean Westover

Re: Real Web Client datetime and timezone

PostPosted: Thu Jan 13, 2011 6:11 pm
by ptalbot
:lol:

How do you create a function in 3.5 then?
You need one to receive a callback from the web page.

Perhaps create a global method, with this code inside:
Code: Select all
var date = new Date(d);
// now do anything you want with this date.
application.output(date);

call it 'callbackMethod'

Then put this in a button onAction event for example:
Code: Select all
var js = "var d = new Date().toUTCString();";
plugins.WebClientUtils.executeClientSideJS(js, globals.callbackMethod, ['d']);