2011-01-21 78 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())); 
相關問題