1

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

Henri Kerola
  • 4,947
  • 1
  • 17
  • 19
aminedev
  • 323
  • 3
  • 9
  • 22

2 Answers2

7

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.

Henri Kerola
  • 4,947
  • 1
  • 17
  • 19
  • Hey thnaks for the answer and information about the WebBrowser Class , But did'nt work it gives always the server Date , after seeing the Documentation i found that the method : public Date getCurrentDate() Returns the current date and time of the browser. This will not be entirely accurate due to varying network latencies, but should provide a close-enough value for most cases. Also note that the returned Date object uses servers default time zone, not the clients. – aminedev Apr 26 '12 at 09:18
  • 1
    The WebBrowser class has other time and timezone related methods too, I think you should be able to calculate time in browser by using those methods. – Henri Kerola Apr 30 '12 at 08:44
0

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.

nexus
  • 2,937
  • 3
  • 17
  • 22
  • 1
    as you can see in Henri Kerola's answer, vaadin already provides a feature to get the date from the client. I didn't know that. – nexus Apr 25 '12 at 17:53