简体   繁体   中英

How to get current System date in SmartGwt application


How to get current system date in Smartgwt application (Merely javascript). I need date to be printed as 25 October 2010 something like this. Currently i am using the following code:

String currentDate ;
java.util.Date date = new Date();
String tempDate = date.toString();
String[] currDate = tempDate.split(" ");
currentDate = currDate[2] + " " + currDate[1] + " "
        + currDate[currDate.length - 1];

But i guess this will not work if the locale of the system/server changes. Can you suggest me any method to get date ?

You can call Javascript method using JSNI:

public native String getLocaleDateString() /*-{
    return new Date().toLocaleDateString();
}-*/;

GWT 2.1 will introduce the new JsDate class:

JsDate.create().toLocaleDateString();

In SmartGWT, there is a DateUtil class that does exactly what you need; see http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/util/DateUtil.html

You can find an usage example on the SmartGWT forums here: http://forums.smartclient.com/showthread.php?t=13920&highlight=DateUtil

Hope this helps.

in smart gwt u can use java classes.

this date will be on client side date .

This will work.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM