Signup/Sign In
LAST UPDATED: JUNE 15, 2020

Java LocalDate getDayOfMonth() Method

This method is used to get day of a month from a date. For example, we have a date 2012/02/15 then this method will return 15 as a day of the month.

It does not takes any argument and can be called using the LocalDate object. The syntax of the method is given below.

Syntax

public int getDayOfMonth()

Parameters

It does not take any parameter.

Return

It returns an integer value.

Time for an Example:

In this example, we are getting day of a month in a date by using the getDayOfMonth() method. This method returns an integer value that shows day of the month.

import java.time.LocalDate;
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.of(2018, 2, 20);
		System.out.println(localDate);
		int day = localDate.getDayOfMonth();
		System.out.println("day of month : "+day);
	}
}


2018-02-20
day of month : 20

Time for another Example:

If we have a date that does not show day of month directly then still we can get a day of the month by using the getDayOfMonth() method. See the below example.

import java.time.LocalDate;
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.ofYearDay(2012, 203);
		System.out.println(localDate);
		int day = localDate.getDayOfMonth();
		System.out.println("day of month : "+day);
	}
}


2012-07-21
day of month : 21

Live Example:

Try with a live example, execute the code instantly with our powerful Online Java Compiler.



About the author:
I am a 3rd-year Computer Science Engineering student at Vellore Institute of Technology. I like to play around with new technologies and love to code.