java - How to get current System date in SmartGwt application - Stack Overflow

How to get current system date in Smartgwt application (Merely javascript). I need date to be printed as


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 ?


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 ?

Share Improve this question edited Oct 25, 2010 at 10:56 JoseK 31.4k14 gold badges107 silver badges133 bronze badges asked Oct 25, 2010 at 10:47 KarthikeyanKarthikeyan 5262 gold badges8 silver badges20 bronze badges 1
  • You should be careful with this. What do you want to acplish with this Date ? You might want to get it from the Server or simply calculate the Date on the Server when the user submits a request. If not you may have wildly different date times based on each of the users clock. – Romain Hippeau Commented Oct 25, 2010 at 11:19
Add a ment  | 

3 Answers 3

Reset to default 3

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./smartgwt/javadoc//smartgwt/client/util/DateUtil.html

You can find an usage example on the SmartGWT forums here: http://forums.smartclient./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.....

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744379925a4571374.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信