Calendar Java Util Example
Few examples to work with calendar apis.
Calendar java util example. Print current time system out println current year is cal. The following example shows the usage of java util calendar set method. Public class calendardemo public static void main string args create a calendar calendar cal calendar getinstance.
Public class calendaraddexample public static void main string args calendar cal calendar getinstance. Calendar calendar calendar getinstance. Following are the fields for java util calendar class static int all styles this is the style specifier for getdisplaynames indicating names in all styles such as january and jan.
Static int am this is the value of the am pm field indicating the period of the day from midnight to just before noon. A calendar object can produce all the calendar field values needed to implement the date time formatting for a particular language and calendar style for example japanese gregorian japanese traditional. Let s see the declaration of java util calendar.
System out println current calendar s day. Public final void set int year int month int date 3. Java calendar class declaration.
Java util calendar set description. Public void set int field int value 2. Java calendar class is an abstract class that provides methods for converting date between a specific instant in time and a set of calendar fields such as month year hour etc.
This java tutorial shows how to use the set method of calendar class of java util package. System out println sdf format calendar gettime. It inherits object class and implements the comparable interface.