* get year, month, today, date, hours, minutes seconds
//Get the browsers date (!!!note: I can't get gmt time zone in eclipse debugger)
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);
4 comments:
A very good starting for the datetime in GWT.
Please tell me How to apply custom format to a Date in GWT 2.0?
I have found the solution
Date resultdate = Calendar.getInstance().getTime();
com.google.gwt.i18n.client.DateTimeFormat dtf = com.google.gwt.i18n.client.DateTimeFormat.getFormat("MM/dd/yyyy");
return dtf.format(resultdate).toString();
Date.getYear etc is deprecated. So do not use that :)
Calendar works only on server side. So on client side consider use of DataTimeFormat class from GWT and Date class:
final DateTimeFormat yearFormat = DateTimeFormat.getFormat("y");
final String year = yearFormat.format(new Date());
Date.getYear() is deprecated but it is used extensively by GWT's DateTimeFormat.
You may as well just use it directly!
Post a Comment