Wednesday, July 3, 2024
HomeLanguagesJavaMonthDay toString() Method in Java with Examples

MonthDay toString() Method in Java with Examples

toString() method of the MonthDay class used to represents this month-day as a String like –08-23.The output will be in the format –MM-dd:
Syntax: 
 

public String toString()

Parameters: This method did not accepts any parameter.
Return value: This method returns a String representation of this MonthDay.
Below programs illustrate the toString() method: 
Program 1: 
 

Java




// Java program to demonstrate
// MonthDay.toString() method
 
import java.time.*;
 
public class GFG {
    public static void main(String[] args)
    {
        // create a MonthDay object
        MonthDay month = MonthDay.parse("--10-12");
 
        // print instance of MonthDay
        System.out.println("YearMonth: "
                           + month.toString());
    }
}


Output: 

YearMonth: --10-12

 

Program 2: 
 

Java




// Java program to demonstrate
// MonthDay.toString() method
 
import java.time.*;
 
public class GFG {
    public static void main(String[] args)
    {
        // create a MonthDay object
        MonthDay month = MonthDay.parse("--08-31");
 
        // print instance of MonthDay
        System.out.println("YearMonth: "
                           + month.toString());
    }
}


Output: 

YearMonth: --08-31

 

References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#toString()
 

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments