Real Web Client datetime and timezone

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!

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)

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:

Put the jar in your /application_server/plugins folder.

Then do something like this:

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);
}

great tip Patrick, thanks!

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)

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

Best way to know is to try it! ;)

I did. It did not work. That’s why I asked. :)

Dean

I suppose the API is too old although it doesn’t look like it.
What kind of error do you have in the log?

“Function keyword found in this script” when click verify button in method editor.

Dean Westover

: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:

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:

var js = "var d = new Date().toUTCString();";
plugins.WebClientUtils.executeClientSideJS(js, globals.callbackMethod, ['d']);