2011-01-21 77 views
9

我经历的GWT教程和进入这一行后,我的IDE抱怨 调用DateTimeFormat.getMediumDateTimeFormat()被弃用:如何替换此弃用的方法调用?

lastUpdatedLabel.setText( “最后更新时间: ” + DateTimeFormat.getMediumDateTimeFormat( ).format(new Date()));

我该如何更换呼叫?

回答

9

this documentation,你需要使用getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM)

+1

Thx,工作。虽然我不得不使用`DATE_TIME_MEDIUM`。 – helpermethod 2011-01-21 16:14:27

1

能不能给我改正或者你的意见,奥利弗·维勒? 也许这对你来说太陈旧了......但我是JAVA和GWT的新手... 我想知道下面的代码是否是这个不赞成使用的方法的一个好的和有效的解决方案。

谷歌教程给这个: https://developers.google.com/web-toolkit/doc/latest/tutorial/codeclient#timestamp

private void updateTable(StockPrice[] prices) { 
    for (int i = 0; i < prices.length; i++) { 
     updateTable(prices[i]); 
    } 

    // Display timestamp showing last refresh. 
    lastUpdatedLabel.setText("Last update : " + DateTimeFormat.getMediumDateTimeFormat().format(new Date())); 
    } 

我把这个代替

private void updateTable(StockPrice[] prices) { 
    for (int i = 0; i < prices.length; i++) { 
     updateTable(prices[i]); 
    } 

    // Display timestamp showing last refresh. 
    DateTimeFormat format = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM); 
    lastUpdatedLabel.setText("Last update : " + format.format(new Date())); 

    } 

不知道为什么谷歌没有更新本教程。

看看这里确认:https://code.google.com/p/google-web-toolkit/issues/detail?id=8241#c3
由于@qbektrix

3

我无法得到最后的答案工作。它只给出日期戳的结果。

试试这个:

lastUpdatedLabel.setText("Last update: " + 
    DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM) 
       .format(new Date())); 
相关问题