Java DateFormatSymbols setShortMonths() Example

DateFormatSymbols class setShortMonths() method example. This example shows you how to use setShortMonths() method.


Syntax is : public void setShortMonths(String[] newShortMonths)
This meethod sets short month strings to the specified string array. For example: "Jan", "Feb", etc.

Here is the code.

/**
 * @(#) SetShortMonthsDateFormatSymbols.java
 * A class representing use of method setShortMonths() of DateFormatSymbols
class in java.text Package.
 * @Version  16-May-2008
 @author   Rose India Team
 */
import java.text.*;

class SetShortMonthsDateFormatSymbols {

    public static void main(String[] args) {

        // Create new DateFormatSymbols object with getInstance() method.
        DateFormatSymbols dFormatSymbols = DateFormatSymbols.getInstance();

        // getShortMonths() method call.
        String[] months = dFormatSymbols.getShortMonths();
        System.out.println("Months in short form : ");
        for (int i = 0; i < months.length; i++) {
            System.out.println(months[i]);
        }

        // setMonths method call.
        String[] str = {"Mahendra""Girish"};
        dFormatSymbols.setShortMonths(str);
        months = dFormatSymbols.getShortMonths();
        System.out.println("Months after setShortMonths() method : ");
        for (int i = 0; i < months.length; i++) {
            System.out.println(months[i]);
        }
    }
}

Output of the program.
Months in short form :
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec

Months after setShortMonths() method :
Mahendra
Girish

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US