Tuesday, 23 January 2018

How to use get method which accepts temporal field of LocalDateTime Class | Java 8 Date and Time


Click here to watch on Youtube : 
https://www.youtube.com/watch?v=cQmDwjJznvk&list=UUhwKlOVR041tngjerWxVccw

LocalDateTimeDemo.java

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

public class LocalDateTimeDemo
{

    public static void main(String[] args)
    {
        LocalDateTime currentDateTime = LocalDateTime.now();
        System.out.println(currentDateTime);

        /*
         * Parameters:
         *
         * field - the field to get, not null
         *
         * Returns:
         *
         * the value for the field
         *
         */

        System.out.println("DAY_OF_WEEK = "
                + currentDateTime.get(ChronoField.DAY_OF_WEEK));

        System.out.println("DAY_OF_YEAR = "
               + currentDateTime.get(ChronoField.DAY_OF_YEAR));

        System.out.println("DAY_OF_MONTH = "
                + currentDateTime.get(ChronoField.DAY_OF_MONTH));

        System.out.println("HOUR_OF_DAY = "
                + currentDateTime.get(ChronoField.HOUR_OF_DAY));

        System.out.println("MINUTE_OF_DAY = "
                + currentDateTime.get(ChronoField.MINUTE_OF_DAY));
    }

}

Output

2018-01-12T09:47:30.097
DAY_OF_WEEK = 5
DAY_OF_YEAR = 12
DAY_OF_MONTH = 12
HOUR_OF_DAY = 9
MINUTE_OF_DAY = 587

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/LocalDateTimeDemo_get_Temporalfield.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/LocalDateTimeDemo_get_Temporalfield

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2732bd5046563d647669928b143687e5dbf4d99f/BasicJava/LocalDateTimeDemo_get_Temporalfield/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment