本文介绍了GWT:在客户端使用 DateTimeFormat,在服务器使用 SimpleDateFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数必须在客户端和服务器上以相同的方式工作并且它格式化日期.

I have a function that must work the same way on both client and server and it formats dates.

if (GWT.isClient())
{
  // Use DateTimeFormat
} else {
  // Use SimpleDateFormat
}

GWT 抱怨:SimpleDateFormat 类型没有可用的源代码.该错误不是致命的(至少在开发模式下),但很烦人且无法抑制它.在 http://groups.google.com/上发现了类似的问题组/google-web-toolkit/browse_thread/thread/981247fca161c287.他们建议:

GWT complains: No source code is available for type SimpleDateFormat. The error is not fatal (at least in dev mode), but annoying and no way to suppress it.Found a similar question on http://groups.google.com/group/google-web-toolkit/browse_thread/thread/981247fca161c287 . There they suggest:

你可以提供一个虚拟的超级资源实现SimpleDateTimeFormat 以便编译.

我试过了.现在 Eclipse 抱怨:

I tried. Now Eclipse complains:

java.text声明的包java.text"与预期的包foo.jre.java.text"SimpleDateFormat.java 不匹配

推荐答案

您必须告诉 Eclipse 不要编译您的超级源代码 Java 文件.如果您使用 Maven,只需将其移动到 src/main/resources;否则,从 Eclipse 的构建路径中排除您的jre".

You have to tell Eclipse not to compile your super-source'd Java file. If you're using Maven, it's simply a matter of moving it to src/main/resources; otherwise, exclude your 'jre' package from Eclipse's build path.

...话虽如此,我宁愿超级采购使用 SimpleDateFormat/DateTimeFormat 的类,和/或将其移动到您超级采购的帮助类.

...that being said, I'd rather super-source the class the uses the SimpleDateFormat/DateTimeFormat, and/or move that to a helper class that you'd super-source.

这篇关于GWT:在客户端使用 DateTimeFormat,在服务器使用 SimpleDateFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 03:42