如何替换这个已弃用的方法调用?

9

我正在学习GWT教程,在输入以下代码后,我的IDE报错:调用DateTimeFormat.getMediumDateTimeFormat()已被废弃:

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

我该如何替换该调用?

4个回答

9
根据这份文档,你需要使用getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM)

3

我无法让上一个答案起作用。它只会返回一个日期戳。

试试这个:

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

1
我能请教您的意见或者纠正吗,Oliver Weiler? 也许这对您来说太老了……但是我刚开始学习JAVA和GWT…… 我想知道下面的代码是否是一个好的、高效的解决方案来替代这个已经过时的方法。
Google教程给出了以下内容: 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


0

这应该是一个注释。 - helpermethod
@qbektrix:看看我的回答...在“用这个代替”下面的第二部分,说的和你完全一样。除此之外,感谢你在结尾处提供的链接。 - Manu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接