Java HijrahChronology from LocalDate

Description

Java HijrahChronology from LocalDate

import java.time.LocalDate;
import java.time.Month;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.Chronology;
import java.time.chrono.HijrahChronology;
import java.time.format.DateTimeFormatter;

public class Main {
  public static String toString(LocalDate localDate, Chronology chrono) {
    ChronoLocalDate cDate;/* w w  w  .  j  av a2s . c  o m*/
    cDate = chrono.date(localDate);
    String pattern = "M/d/yyyy GGGGG";
    DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(pattern);
    return dateFormatter.format(cDate);
  }

  public static void main(String[] args) {
    LocalDate date = LocalDate.of(2020, Month.OCTOBER, 29);
    System.out.printf("%s%n", toString(date, HijrahChronology.INSTANCE));

  }
}



PreviousNext

Related