Java LocalDateTime get field value

Description

Java LocalDateTime get field value

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(now.get(ChronoField.YEAR)); 
    System.out.println(now.get(ChronoField.MONTH_OF_YEAR)); 
    System.out.println(now.get(ChronoField.DAY_OF_MONTH)); 
    System.out.println(now.get(ChronoField.HOUR_OF_DAY));
    System.out.println(now.get(ChronoField.HOUR_OF_AMPM)); 
    System.out.println(now.get(ChronoField.AMPM_OF_DAY));

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



PreviousNext

Related