Java 客户端GWT中字符串和日期之间的转换

Java 客户端GWT中字符串和日期之间的转换,java,gwt,type-conversion,Java,Gwt,Type Conversion,使用SimpleDataFormat是Java中进行字符串日期转换的标准方法 但是这个类在GWT中不存在,所以我们不能在GWT客户端代码中使用它 那么,进行此转换的标准/推荐方法是什么?如中所示,这可能会有所帮助 public class DateTimeFormatExample implements EntryPoint { public void onModuleLoad() { Date today = new Date(); // prints Tue Dec

使用
SimpleDataFormat
是Java中进行字符串日期转换的标准方法

但是这个类在GWT中不存在,所以我们不能在GWT客户端代码中使用它

那么,进行此转换的标准/推荐方法是什么?

如中所示,这可能会有所帮助

public class DateTimeFormatExample implements EntryPoint {

  public void onModuleLoad() {
    Date today = new Date();

    // prints Tue Dec 18 12:01:26 GMT-500 2007 in the default locale.
    GWT.log(today.toString(), null);

    // prints 12/18/07 in the default locale
    GWT.log(DateTimeFormat.getShortDateFormat().format(today), null);

    // prints December 18, 2007 in the default locale
    GWT.log(DateTimeFormat.getLongDateFormat().format(today), null);

    // prints 12:01 PM in the default locale
    GWT.log(DateTimeFormat.getShortTimeFormat().format(today), null);

    // prints 12:01:26 PM GMT-05:00 in the default locale
    GWT.log(DateTimeFormat.getLongTimeFormat().format(today), null);

    // prints Dec 18, 2007 12:01:26 PM in the default locale
    GWT.log(DateTimeFormat.getMediumDateTimeFormat().format(today), null);

    // A custom date format
    DateTimeFormat fmt = DateTimeFormat.getFormat("EEEE, MMMM dd, yyyy");
    // prints Monday, December 17, 2007 in the default locale
    GWT.log(fmt.format(today), null);
  }
}
如中的示例所示,这可能会有所帮助

public class DateTimeFormatExample implements EntryPoint {

  public void onModuleLoad() {
    Date today = new Date();

    // prints Tue Dec 18 12:01:26 GMT-500 2007 in the default locale.
    GWT.log(today.toString(), null);

    // prints 12/18/07 in the default locale
    GWT.log(DateTimeFormat.getShortDateFormat().format(today), null);

    // prints December 18, 2007 in the default locale
    GWT.log(DateTimeFormat.getLongDateFormat().format(today), null);

    // prints 12:01 PM in the default locale
    GWT.log(DateTimeFormat.getShortTimeFormat().format(today), null);

    // prints 12:01:26 PM GMT-05:00 in the default locale
    GWT.log(DateTimeFormat.getLongTimeFormat().format(today), null);

    // prints Dec 18, 2007 12:01:26 PM in the default locale
    GWT.log(DateTimeFormat.getMediumDateTimeFormat().format(today), null);

    // A custom date format
    DateTimeFormat fmt = DateTimeFormat.getFormat("EEEE, MMMM dd, yyyy");
    // prints Monday, December 17, 2007 in the default locale
    GWT.log(fmt.format(today), null);
  }
}
检查是否有用?参见检查是否有用?参见