import java.util.Calendar;
import java.util.Formatter;
public class ExMonthFormates {
public static void main(String args[]) {
// create object of date formatter class.
Formatter fmt = new Formatter();
// create object of calendar class.
Calendar cal = Calendar.getInstance();
fmt = new Formatter();
// print month in different ways.
fmt.format("%tB %tb %tm", cal, cal, cal);
System.out.println(fmt);
}
}
Output
November Nov 11
We are creating a main class ExMonthFormates, but here we are using two different packages java.util.Calendar and java.util.Formatter for using methods of these class. After that create an object fmt using formatter class because formatter class provides justification and alignment of formats like numeric, string and date/time. Next, we have to create the calendar class object to convert the instant in time and set of calendar field.
Now, assigning the value into the object fmt (fmt = new Formatter()).
Displaying the format by using %tB %tb %tm, these display the date month name and number and System.out.println(fmt) will print this format on the same line.
Program
Output
We are creating a main class ExMonthFormates, but here we are using two different packages java.util.Calendar and java.util.Formatter for using methods of these class. After that create an object fmt using formatter class because formatter class provides justification and alignment of formats like numeric, string and date/time. Next, we have to create the calendar class object to convert the instant in time and set of calendar field.
Now, assigning the value into the object fmt (fmt = new Formatter()).
Displaying the format by using %tB %tb %tm, these display the date month name and number and System.out.println(fmt) will print this format on the same line.