How to display Month Name like MMM format in Java

This example we will show you how to Display Month name in MMM format. To display month name in java we will have two ways

With Formatter class

import java.util.Calendar;
import java.util.Formatter;

public class Test{
    public static void main(String args[]) {
        Formatter fmt = new Formatter();
        Calendar cal = Calendar.getInstance();
        fmt = new Formatter();
        fmt.format("%tB %tb %tm", cal, cal, cal);



April Apr 04



With SimpleDateFormat

package com.rrtutors.lib;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Test {
    public static void main(String[] args) {
        SimpleDateFormat f = new SimpleDateFormat("MMM");
        SimpleDateFormat f1 = new SimpleDateFormat("dd");
        SimpleDateFormat f2 = new SimpleDateFormat("a");
        int h;

        if(Calendar.getInstance().get(Calendar.HOUR)== 0)h = 12;
        else h = Calendar.getInstance().get(Calendar.HOUR);

        String filename="Current Date is :"
                +" "+f1.format(new Date())
                +" "+f.format(new Date())
                +" "+h+f2.format(new Date());



Current Date is : 05 Apr 10PM

JAVA File IO examples

JAVA Date & Time Progamming Examples