开发者

How to replace this deprecated method call?

开发者 https://www.devze.com 2023-02-06 14:06 出处:网络
I\'m going through the GWT Tutorials and after entering this line, my IDE complains that the call to DateTimeFormat.getMediumDateTimeFormat() is deprecated:

I'm going through the GWT Tutorials and after entering this line, my IDE complains that the call to DateTimeFormat.getMediumDateTimeFormat() is deprecated:

lastUpdatedLabel.setText("Last update: " + DateTimeFormat.getMediumDat开发者_运维知识库eTimeFormat().format(new Date()));

How do I have to replace the call?


According to this documentation, you need to use getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM)


I could not get the last answer to work. It gives the same results with just a date stamp.

Try this:

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


Could I have your correction or maybe your opinion, Oliver Weiler ? Maybe it is too old for you... but I'm new in JAVA and GWT... I want to know if this following code is a good and efficient solution to this deprecated method.

Google Tutorial give this : 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()));
  }

I put this instead

  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()));

  }

Don't know why Google didn't update this tutorial.

Look a confirmation here : https://code.google.com/p/google-web-toolkit/issues/detail?id=8241#c3
Thanks to @qbektrix


@Manu, you can replace

DateTimeFormat.getMediumDateTimeFormat().format(new Date())

with

DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM).format(new Date())

It seems like an authentic GWT team answer as i found it at https://code.google.com/p/google-web-toolkit/issues/detail?id=8241#c3

0

精彩评论

暂无评论...
验证码 换一张
取 消