Monday, 3 October 2011

Fetch system time using gwt


SYSTEM TIME

package com.client;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class systemtime implements EntryPoint {
 
 
  private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {

     
      Date date = new Date();
      int Month = date.getMonth();
      int Day = date.getDate();
      int Year = date.getYear();
      int Hour = date.getHours();
      int min = date.getMinutes();
      int sec = date.getSeconds();
      int tz = date.getTimezoneOffset();
      int UnixTimeStamp = (int) (date.getTime() * .001);

      //get unix time stamp example (seconds)
      Long lTimeStamp = date.getTime(); //time in milleseconds since the epoch
      int iTimeStamp = (int) (lTimeStamp * .001); //(Cast) to Int from Long, Seconds since epoch
      String sTimeStamp = Integer.toString(iTimeStamp); //seconds to string

      //get the gmt date - will show tz offset in string in browser, not eclipse debug window
      String TheDate = date.toString();

      //render date to root panel in gwt
      Label label = new Label(TheDate);
      RootPanel.get().add(label);
     
     
  }
}