The month part of the Calendar date. - Java java.util

Java examples for java.util:Month

Description

The month part of the Calendar date.

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar c = Calendar.getInstance();
        System.out.println(getMonth(c));
    }//w w  w  .j  a  v a2s  .  c o  m

    /**
     * The month part of the Calendar date.
     * @param c the Calendar from which to extract the month
     * @return The month as a String (e.g., Jul)
     */
    public static String getMonth(Calendar c) {
        SimpleDateFormat f = new SimpleDateFormat("MMM");
        return f.format(c.getTime()).toString();
    }
}

Related Tutorials