Tuesday 23 January 2018

How to use of method of LocalDateTime Class | Java 8 Date and Time


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

LocalDateTimeDemo1.java

import java.time.LocalDateTime;
import java.time.Month;

public class LocalDateTimeDemo1
{

    public static void main(String[] args)
    {
        /*
         * Parameters:
         *
         * year - the year to represent, from MIN_YEAR to MAX_YEAR
         *
         * month - the month-of-year to represent, not null
         *
         * dayOfMonth - the day-of-month to represent, from 1 to 31
         *
         * hour - the hour-of-day to represent, from 0 to 23
         *
         * minute - the minute-of-hour to represent, from 0 to 59
         *
         * Returns:
         *
         * the local date-time, not null
         */


        LocalDateTime localDateTime = LocalDateTime.of(2020, Month.MARCH, 30, 6,
                30);
        System.out.println(localDateTime);

    }

}

Output

2020-03-30T06:30

LocalDateTimeDemo2.java

import java.time.LocalDateTime;
import java.time.Month;

public class LocalDateTimeDemo2
{

    public static void main(String[] args)
    {
        /*
         * Parameters:
         *
         * year - the year to represent, from MIN_YEAR to MAX_YEAR
         *
         * month - the month-of-year to represent, not null
         *
         * dayOfMonth - the day-of-month to represent, from 1 to 31
         *
         * hour - the hour-of-day to represent, from 0 to 23
         *
         * minute - the minute-of-hour to represent, from 0 to 59
         *
         * second - the second-of-minute to represent, from 0 to 59
         *
         * Returns:
         *
         * the local date-time, not null
         */


        LocalDateTime localDateTime = LocalDateTime.of(2020, Month.MARCH, 30,
                6, 30, 59);
        System.out.println(localDateTime);

    }

}

Output

2020-03-30T06:30:59

LocalDateTimeDemo3.java

import java.time.LocalDateTime;
import java.time.Month;

public class LocalDateTimeDemo3
{

    public static void main(String[] args)
    {
        /*
         * Parameters:
         *
         * year - the year to represent, from MIN_YEAR to MAX_YEAR
         *
         * month - the month-of-year to represent, not null
         *
         * dayOfMonth - the day-of-month to represent, from 1 to 31
         *
         * hour - the hour-of-day to represent, from 0 to 23
         *
         * minute - the minute-of-hour to represent, from 0 to 59
         *
         * second - the second-of-minute to represent, from 0 to 59
         *
         * nanoOfSecond - the nano-of-second to represent, from 0 to
         * 999,999,999
         *
         * Returns:the local date-time, not null
         */


        LocalDateTime localDateTime = LocalDateTime.of(2020, Month.MARCH, 30,
                6, 30, 59, 600);
        System.out.println(localDateTime);

    }

}

Output

2020-03-30T06:30:59.000000600

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

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

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