Метод DateFormatSymbols getMonths () в Java с примерами
Метод getMonths () класса DateFormatSymbols в Java используется для получения названия месяцев календаря в строковом формате.
Синтаксис:
общедоступная строка [] getMonths ()
Параметры: метод не принимает никаких параметров.
Возвращаемые значения: метод возвращает название месяцев в строковом формате.
Ниже программы иллюстрируют использование метода getMonths ().
Example 1:
// Java code to demonstrate getMonths() import java.text.DateFormatSymbols; public class DateFormat_Main { public static void main(String args[]) { int i; // Initializing DateFormatSymbols String months[] = new DateFormatSymbols().getMonths(); for (i = 0 ; i < months.length - 1 ; i++) { // Displaying the months System.out.println( "Month = " + months[i]); } } } |
Month = January Month = February Month = March Month = April Month = May Month = June Month = July Month = August Month = September Month = October Month = November Month = December
Example 2:
// Java code to demonstrate getMonths() import java.text.DateFormatSymbols; public class DateFormat_Main { public static void main(String args[]) { int i; // Initializing DateFormatSymbols String months[] = new DateFormatSymbols().getMonths(); for (i = 0 ; i < months.length / 2 ; i++) { // Displaying the months System.out.println( "Month " + i + " = " + months[i]); } } } |
Month 0 = January Month 1 = February Month 2 = March Month 3 = April Month 4 = May Month 5 = June
Ссылка: https://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#getMonths–
Вниманию читателя! Не переставай учиться сейчас. Ознакомьтесь со всеми важными концепциями Java Foundation и коллекций с помощью курса "Основы Java и Java Collections" по доступной для студентов цене и будьте готовы к работе в отрасли. Чтобы завершить подготовку от изучения языка к DS Algo и многому другому, см. Полный курс подготовки к собеседованию .