MonthDay from() method in Java


An instance of a MonthDay object can be obtained from a Temporal object using the from() method in the MonthDay class in Java. This method requires a single parameter i.e. the Temporal object and it returns the MonthDay object that is obtained from the Temporal object.

A program that demonstrates this is given as follows

Example

 Live Demo

import java.time.*;
   public class Main {
      public static void main(String[] args) {
      MonthDay md = MonthDay.from(ZonedDateTime.now());
      System.out.println("The MonthDay is: " + md);
   }
}

Output

The MonthDay is: --02-22

Now let us understand the above program.

The instance of the MonthDay object is obtained from the Temporal object using the from() method and then it is displayed. A code snippet that demonstrates this is as follows:

MonthDay md = MonthDay.from(ZonedDateTime.now());
System.out.println("The MonthDay is: " + md);

Updated on: 30-Jul-2019

36 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements