Wednesday 24 January 2018

How to convert LocalDateTime to LocalDate and LocalTime | LocalDateTime Class


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

LocalDateTimeDemo.java

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class LocalDateTimeDemo
{

    public static void main(String[] args)
    {
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDateTime = " + localDateTime);
       
       
        /*
         * Returns the date part of this date-time, not null.
         */

        LocalDate localDate = localDateTime.toLocalDate();
        System.out.println("localDate = " + localDate);

        /*
         * Returns the time part of this date-time, not null.
         */

        LocalTime localTime = localDateTime.toLocalTime();
        System.out.println("localTime = " + localTime);

    }

}

Output

localDateTime = 2018-01-17T09:41:13.709
localDate = 2018-01-17
localTime = 09:41:13.709

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

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

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