Simple Date Format Day in Month Example in java

This example shows you how to get day value of month using SimpleDateFormat object, we can use the “dd” format for day value of month in SimpleDateFormat as shown in below example.

package com.java.connect.date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class SimpleDateFormatDayInMonthExample {
    public static void main(String[] args) {
        // Get the simple date format object by passing the format in string
        SimpleDateFormat format = new SimpleDateFormat("dd");
        // get the date in String format by passing current date
        // in format method of simple date format object
        Calendar date = Calendar.getInstance();
        String dateString = format.format(date.getTime());
        // Print the formated date.
        System.out.println("The Current Date's day in the month is : " + dateString);
    }
}

The output of the above example will be as:

The Current Date's day in the month is : 07