There is a code for Android, the goal to display the name of the month:

day_of_month = (TextView)findViewById(R.id.day_of_month); day_of_week = (TextView)findViewById(R.id.day_of_week); String month_s = String.format("%1$tB",new Date()); String day_s = String.format("%1$tA",new Date()); month.setText(month_s); day_of_week.setText(day_s); 

Everything is good, except for the case of the month: it is displayed as March, February, September, etc., that is, in the genitive case.

Thanks to the response, the code acquired the following form:

 SimpleDateFormat format = new SimpleDateFormat("yyyy;LLLL;dd;EEEE"); String date_string = String.format("%s",format.format(new Date())); String[] date_array = date_string.split(";"); year.setText(date_array[0]); month.setText(date_array[1]); day_of_month.setText(","+date_array[2]); day_of_week.setText(date_array[3]); 

    1 answer 1

    In my opinion, through String.format - no way. With API 9, you can use SimpleDateFormat with the parameter "L" (stand-alone month):

     SimpleDateFormat format = new SimpleDateFormat( "LLLL" ); System.out.printf( "sdf: %s%n", format.format( new Date() ) ); // sdf: Март 

    The same parameter for the day of the week is "c" , although this is not important for the Russian language.

    • , thanks, it helped. Where did you find this form "LLLL"? I didn’t see it here docs.oracle.com/javase/7/docs/api/java/text/… - NoAppYet
    • one
      @NoAppYet For android it is better to look at the documentation on their website, the standard classes sometimes differ slightly. Another link is the dock from SE 7, in SE 8 SimpleDateFormat supports "LLLL". - zRrr