Java DateFormat.Field getCalendarField() Example
DateFormat.Field class getCalendarField() method example. This example shows you how to use getCalendarField() method.
Syntax is : public int getCalendarField()
Method returns the Calendar field associated with this attribute. For example, if this represents the hours field of a Calendar, this would
return Calendar.HOUR. If there is no corresponding Calendar constant, this will return -1.
Here is the code.
/**
* @(#) GetCalendarFieldDateFormatField.java
* A class representing use of method getCalendarField() of DateFormat.Field
class in java.text Package.
* @Version 13-May-2008
* @author Rose India Team
*/
import java.util.*;
import java.text.*;
class GetCalendarFieldDateFormatField extends DateFormat.Field {
GetCalendarFieldDateFormatField(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());
// Create new object of GetCalendarFieldDateFormatField class.
GetCalendarFieldDateFormatField obj = new
GetCalendarFieldDateFormatField("Mahendra", Calendar.DATE);
// getCalendarField method call.
int calendarField = obj.getCalendarField();
System.out.print("Calendar field of object obj : " + calendarField);
}
} |
Output of the program.
Date by Date class : Fri Jun 13 18:12:19 GMT+05:30 2008
Calendar field of object obj : 5
|
|