简体   繁体   English

如何获得GWT中的月/日名称?

[英]How can I get the Month/Weekday names in GWT?

How can I get the Month/Weekday names in GWT? 如何获得GWT中的月/日名称?

I try it like this, but there must exist a better solution for this problem (i hope :) ): 我这样尝试,但是必须存在一个更好的解决方案(我希望:)):

public String getLocalizedName() {
    switch( this ) {
        case Januar:
            return getMonth( 1 );
        case February:
            return getMonth( 2 );
        case March:
            return getMonth( 3 );
        case April:
            return getMonth( 4 );
        case May:
            return getMonth( 5 );
        case June:
            return getMonth( 6 );
        case July:
            return getMonth( 7 );
        case August:
            return getMonth( 8 );
        case September:
            return getMonth( 9 );
        case October:
            return getMonth( 10 );
        case November:
            return getMonth( 11 );
        case December:
            return getMonth( 12 );
    }
    return "";
}

private String getMonth( int month ) {

    return DateTimeFormat.getFormat( DateTimeFormat.PredefinedFormat.MONTH_ABBR ).format( new Date( 2011, month, 1 ) );
}

Not sure if you want to format or just a list of the months/days. 不确定要格式化还是仅列出月/日列表。 The localized string can be obtained from DateTimeFormatInfo : 本地化的字符串可以从DateTimeFormatInfo获得:

//returns a String array with localized names of the months
String[] months = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull();

//returns a String array with localized names of days of the week
String[] weekdays = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().weekdaysFull();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM