Java DateTimeFormatterBuilder Class

Description

Java DateTimeFormatterBuilder Class


import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.TextStyle;
import java.time.temporal.ChronoField;

public class Main {
  public static void main(String[] args) {
    DateTimeFormatter formatter = new DateTimeFormatterBuilder()
        .appendLiteral("Christmas in ")
        .appendValue(ChronoField.YEAR)
        .appendLiteral(" is on ")
        .appendText(ChronoField.DAY_OF_WEEK, TextStyle.FULL_STANDALONE)
        .toFormatter();//from   w w w.ja  v a 2s  . c  o m
    LocalDate ld = LocalDate.of(2020, 12, 25);
    String str = ld.format(formatter);
    System.out.println(str);
  }
}



PreviousNext

Related