Java Date Time - MonthDay format(DateTimeFormatter formatter) example








MonthDay format(DateTimeFormatter formatter) formats this month-day using the specified formatter.

Syntax

format has the following syntax.

public String format(DateTimeFormatter formatter)

Example

The following example shows how to use format.

import java.time.MonthDay;
import java.time.format.DateTimeFormatter;
/*from w w  w .  jav  a  2s . c  o  m*/
public class Main {
  public static void main(String[] args) {
    MonthDay m = MonthDay.now();
    String n = m.format(DateTimeFormatter.ofPattern("M"));
    System.out.println(n);

  }
}

The code above generates the following result.