Java Date Time Java Java API
Class:
java.time.MonthDay
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
|