How do you format the day of the month to say “11th”, “21st” or “23rd” (ordinal indicator)?

后端 未结 20 969
逝去的感伤
逝去的感伤 2020-11-22 02:41

I know this will give me the day of the month as a number (11, 21, 23):

SimpleDateFormat formatDayOfMonth = new Simple         


        
20条回答
  •  渐次进展
    2020-11-22 02:55

    public String getDaySuffix(int inDay)
    {
      String s = String.valueOf(inDay);
    
      if (s.endsWith("1"))
      {
        return "st";
      }
      else if (s.endsWith("2"))
      {
        return "nd";
      }
      else if (s.endsWith("3"))
      {
        return "rd";
      }
      else
      {
        return "th";
      }
    }
    

提交回复
热议问题