Home Java Date Examples

SimpleDateFormat Day of Week in Month Example

This example show you how to get the day of week in month using SimpleDateFormat object, we need to pass the format as "FF" while creating SimpleDateFormat object and we can format any date using SimpleDateFormat object as shown in below example.

package com.java.connect.date;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class SimpleDateFormatDayOfWeekInMonthExample {
	public static void main(String[] args) {
		// Get the simple date format object by passing the format in string
		SimpleDateFormat format = new SimpleDateFormat("FF");
		// get the date in String format by passing current date
		// in format method of simple date format object
		Calendar originalDate = Calendar.getInstance();
		System.out.println("The original date is : " + originalDate.getTime());
		String dateString = format.format(originalDate.getTime());
		// Print the formated date.
		System.out.println("The day of week in month is : " + dateString);
	}
}

The output of the above example will be as:

The original date is : Sat May 07 19:26:21 GMT 2011
The day of week in month is : 01