Simple Date Format Day in Year Example in java

This example shows you how to get the day of year for a particular date, for example we are using the current date and find out it is the which day of year as shown in below example.

import java.text.SimpleDateFormat;
import java.util.Calendar;
public class SimpleDateFormatDayInYearExample {
    public static void main(String[] args) {
        // Get the simple date format object by passing the format in string
        SimpleDateFormat format = new SimpleDateFormat("DDD");
        // 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("Today is the " + dateString + "th day of the year");

The output of above example will be as:

Today is the 127th day of the year