Java ChronoField enum

Introduction

Some of the fields from ChronoField enum are as follows:

  • AMPM_OF_DAY
  • CLOCK_HOUR_OF_AMPM
  • CLOCK_HOUR_OF_DAY
  • DAY_OF_MONTH
  • DAY_OF_WEEK
  • DAY_OF_YEAR
  • ERA
  • HOUR_OF_AMPM
  • HOUR_OF_DAY
  • INSTANT_SECONDS
  • MINUTE_OF_HOUR
  • MONTH_OF_YEAR
  • SECOND_OF_MINUTE
  • YEAR
  • YEAR_OF_ERA
  • ...
  • ...

import java.time.LocalDateTime;
import java.time.temporal.ChronoField;

public class Main {
  public static void main(String[] args) {
    LocalDateTime now = LocalDateTime.now();
    System.out.println("Current Date Time: " + now);
    System.out.println("Year: " + now.get(ChronoField.YEAR));
    System.out.println("Month: " + now.get(ChronoField.MONTH_OF_YEAR));
    System.out.println("Day: " + now.get(ChronoField.DAY_OF_MONTH));
    System.out.println("Hour-of-day: " + now.get(ChronoField.HOUR_OF_DAY));
    System.out.println("Hour-of-AMPM: " + now.get(ChronoField.HOUR_OF_AMPM));
    System.out.println("AMPM-of-day: " + now.get(ChronoField.AMPM_OF_DAY));

  }/*  ww w .j  a v a 2s .  c  o m*/
}



PreviousNext

Related