Date currentDate = new Date(); int dayOfMonth = currentDate.getDate(); System.out.println("Today is the " + dayOfMonth + "th day of the month.");
Date someDate = new Date("December 17, 1995 03:24:00"); int dayOfMonth = someDate.getDate(); System.out.println("The day of the month for December 17, 1995 is " + dayOfMonth);This code creates a new Date object representing December 17, 1995 and gets the day of the month from it using the getDate method. It then prints out a message stating the day of the month. Both of these examples use the java.util.Date class from the java.util package library.