Close

Java Date Time - MonthDay.parse() 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 parse(CharSequence text)

Obtains an instance of MonthDay from a text string of format --MM-dd.



public static MonthDay parse(CharSequence text,
                             DateTimeFormatter formatter)

Obtains an instance of MonthDay from a text string using a specific formatter.


Examples


package com.logicbig.example.monthday;

import java.time.MonthDay;

public class ParseExample {

public static void main(String... args) {
MonthDay m = MonthDay.parse("--11-21");
System.out.println(m);

m = MonthDay.parse("--01-01");
System.out.println(m);
}
}

Output

--11-21
--01-01




package com.logicbig.example.monthday;

import java.time.MonthDay;
import java.time.format.DateTimeFormatter;

public class ParseExample2 {

public static void main(String... args) {
DateTimeFormatter f = DateTimeFormatter.ofPattern("d/M");
MonthDay m = MonthDay.parse("21/1", f);
System.out.println(m);
}
}

Output

--01-21




See Also