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

十年热恋 提交于 2019-12-24 07:08:42

问题


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


回答1:


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 {

    @Override
    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.




回答2:


Vaadin runs on server side, so everything you do there corresponds to the server itself. For your problem you can probably create a vaadin widget to get clients time(-zone) and pass it to the server.



来源:https://stackoverflow.com/questions/10313668/how-to-get-the-time-of-computer-and-not-server-java-vaadin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!