Java Program to Display Current Month in the (MMM) Format

bookmark

import java.text.SimpleDateFormat;
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        //create an object of SimpleDateFormat as ‘s1’ with the argument as ‘MMM’.
        SimpleDateFormat s1 = new SimpleDateFormat("MMM");
        // Declare a string variable as ‘month1’ and initialize it to the current date and time using an inbuild method of SimpleDateFormat as s1.format(new Date())
        String month1= s1.format(new Date());
        //Print the result in MMM format
        System.out.println("Month in MMM format = "+month1);
        //create an object of SimpleDateFormat as ‘s2’ with the argument as ‘MMMM’.
        SimpleDateFormat s2 = new SimpleDateFormat("MMMM");
        // Declare a string variable as ‘month2’ and initialize it to the current date and time using an inbuild method of SimpleDateFormat as s2.format(new Date())
        String month2 = s2.format(new Date());
        //Print the result in MMMM format
        System.out.println("Month in MMMM format = "+month2);
    }
}

 


Output:

Month in MMM format = Jun
Month in MMMM format = June