SORU
24 EKİM 2010, Pazar


Nasıl Ayın gün söylemek format mı&; 11" quot;, &; 21" quot; veya &Java;23" quot;?

Bu bir numara (11, , *21*4)bana gün verecek biliyorum:

SimpleDateFormat formatDayOfMonth = new SimpleDateFormat("d");

Ama ne biçim Ayın günü ** 13 11th, 21st 23rd say eklemek için Java mı?

CEVAP
25 EKİM 2010, PAZARTESİ


// http://code.google.com/p/guava-libraries
import static com.google.common.base.Preconditions.*;

String getDayOfMonthSuffix(final int n) {
    checkArgument(n >= 1 && n <= 31, "illegal day of month: "   n);
    if (n >= 11 && n <= 13) {
        return "th";
    }
    switch (n % 10) {
        case 1:  return "st";
        case 2:  return "nd";
        case 3:  return "rd";
        default: return "th";
    }
}

@Masa kaliatech güzel, ama aynı bilgileri tekrarladı olduğu bir hata için şans açar. Böyle bir hata gerçekten var masa için 7tn, 17tn 27tn (Bu hata olabilir sabit zaman geçtikçe çünkü bu sıvı, doğa StackOverflow, böylece kontrol the version history on the answer için bkz: hata).

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • 07cadikiz07

    07cadikiz07

    17 EKİM 2007
  • DJPixcell

    DJPixcell

    20 NİSAN 2007
  • TheFlightsuit

    TheFlightsui

    22 HAZİRAN 2009