Close

Java Date Time - MonthDay.of() Examples

Java Date Time Java Java API 


Class:

java.time.MonthDay

java.lang.Objectjava.lang.Objectjava.time.MonthDayjava.time.MonthDayjava.time.temporal.TemporalAccessorTemporalAccessorjava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public static MonthDay of(Month month,
                          int dayOfMonth)

This method creates an instance of MonthDay for the provided month enum and dayOfMonth value. The specified dayOfMonth must be a valid day for a month.



public static MonthDay of(int month,
                          int dayOfMonth)

This method creates an instance of MonthDay for the provided month and dayOfMonth values. The specified month and dayOfMonth values must be valid for a month and the day within that month.


Examples


package com.logicbig.example.monthday;

import java.time.Month;
import java.time.MonthDay;

public class OfExample {

public static void main(String... args) {
MonthDay m = MonthDay.of(Month.SEPTEMBER, 10);
System.out.println(m);
}
}

Output

--09-10




package com.logicbig.example.monthday;

import java.time.MonthDay;

public class OfExample2 {

public static void main(String... args) {
MonthDay m = MonthDay.of(10, 6);
System.out.println(m);
}
}

Output

--10-06




See Also