1
使用SimpleDateFormat
是一種標準方式來執行字符串< - > Java中的日期轉換。客戶端GWT中的字符串和日期之間的轉換
但是這個類不在GWT JRE Emulation library中,所以我們不能在GWT客戶端代碼中使用它。
什麼是標準/推薦的做這種轉換的方式呢?
使用SimpleDateFormat
是一種標準方式來執行字符串< - > Java中的日期轉換。客戶端GWT中的字符串和日期之間的轉換
但是這個類不在GWT JRE Emulation library中,所以我們不能在GWT客戶端代碼中使用它。
什麼是標準/推薦的做這種轉換的方式呢?
如Date Time Format
中的示例所示,這可能有幫助。
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);
}
}
優秀的答案,非常感謝! –
http://stackoverflow.com/questions/3543832/convert-string-to-date-on-gwt – Krrose27
檢查,如果[日期時間格式(HTTP://google-web-toolkit.googlecode。 com/svn/javadoc/1.5/com/google/gwt/i18n/client/DateTimeFormat.html)有幫助嗎? –
請參閱https://developers.google.com/web-toolkit/doc/latest/DevGuideI18n –