Close

Java Date Time - MonthDay.from() 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

Method:

public static MonthDay from(TemporalAccessor temporal)

This methods creates an instance of MonthDay from the provided temporal object. The provided temporal object must have MONTH_OF_YEAR and DAY_OF_MONTH fields.


Examples


package com.logicbig.example.monthday;

import java.time.*;
import java.time.temporal.TemporalAccessor;

public class FromExample {

public static void main(String... args) {
from(LocalDate.now());
from(LocalDateTime.now());
from(OffsetDateTime.now());
from(ZonedDateTime.now());
from(MonthDay.now());
}

private static void from(TemporalAccessor t) {
MonthDay m = MonthDay.from(t);
System.out.printf("%16s > %s > %s%n",
t.getClass().getSimpleName(),
t, m);

}
}

Output

       LocalDate > 2017-05-01 > --05-01
LocalDateTime > 2017-05-01T15:55:20.236 > --05-01
OffsetDateTime > 2017-05-01T15:55:20.237-05:00 > --05-01
ZonedDateTime > 2017-05-01T15:55:20.237-05:00[America/Chicago] > --05-01
MonthDay > --05-01 > --05-01




See Also