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

Java examples for java.util:Day

Description

The day 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(getDay(c));
    }/*from   w  ww .  j  a  v a2s  . co m*/

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

Related Tutorials