aminedev aminedev -4 years ago 144
Java Question

How to get the time of Computer and not server Java vaadin

Hey how to get the time of the computer and not the server using vaadin because getDate return to me the time of the server but i want the client computer time ??

Answer Source

Vaadin has a class called WebBrowser that provides useful information about the client (browser):

You can access the current WebBrowser instance for example as follows:

public class MyApplication extends Application {

    public void init() {
        setMainWindow(new Window());

        ApplicationContext context = this.getContext();
        if (context instanceof WebApplicationContext) {
            WebBrowser webBrowser = ((WebApplicationContext) this.getContext()).getBrowser();

            Date now = webBrowser.getCurrentDate(); // Returns the current date and time on the browser

For more information about the WebBrowser class, see its JavaDocs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download