Tuesday, 16 January 2018

How to use now methods of Java 8 LocalDate Class to get the current date | Java 8 Date and Time


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

LocalDateDemo.java

import java.time.Clock;
import java.time.LocalDate;
import java.time.ZoneId;

public class LocalDateDemo
{
    public static void main(String[] args)
    {
        /*
         * Returns:the current date using the system clock and default
         * time-zone, not null
         */

        LocalDate date1 = LocalDate.now();
        System.out.println(date1);

        Clock clock = Clock.systemUTC();
        /*
         * Parameters:
         *
         * clock - the clock to use, not null
         *
         * Returns:the current date, not null
         */


        LocalDate date2 = LocalDate.now(clock);
        System.out.println(date2);

        ZoneId zoneId = ZoneId.systemDefault();
        /*
         * Parameters:
         *
         * zone - the zone ID to use, not null
         *
         * Returns:the current date using the system clock, not null
         */

        LocalDate date3 = LocalDate.now(zoneId);
        System.out.println(date3);
    }

}

Output

2018-01-07
2018-01-07
2018-01-07

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/f50b0477cba623e7ace08d1d7966409dcc9e7b40/BasicJava/LocalDateDemo_now_methods/?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