问题
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