Java DateFormat.Field ofCalendarField() Example

DateFormat.Field class ofCalendarField() method example. This example shows you how to use ofCalendarField() method.


Syntax is : public static DateFormat.Field ofCalendarField(int calendarField)
Method returns the Field constant that corresponds to the Calendar constant calendarField. If there is no direct mapping between the
Calendar constant and a Field, null is returned.

Here is the code.
/**
 * @(#) OfCalendarFieldDateFormatField.java
 * A class representing use of method ofCalendarField() of DateFormat.Field
class in java.text Package.
 * @Version  13-May-2008
 @author   Rose India Team
 */
import java.util.*;
import java.text.*;

class OfCalendarFieldDateFormatField extends DateFormat.Field {

    OfCalendarFieldDateFormatField(String str, int value) {
        super(str, value);
    }
    public static void main(String[] args) {

        // Create new Date object that will be initialized to the current date.
        Date date = new Date();
        System.out.println("Date  by  Date  class    : " + date.toString());

        // ofCalendarField is static method,method call without object.
        DateFormat.Field dateField = OfCalendarFieldDateFormatField.
                ofCalendarField(Calendar.AM_PM);
        System.out.print("Field constant is : " + dateField);
    }
}

Output of the program.
 Date  by  Date  class    : Fri Jun 13 18:14:59 GMT+05:30 2008
Field constant is : java.text.DateFormat$Field(am pm)

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

HOME | COPYRIGHT | CONTACT US