Click here to watch on Youtube :
https://www.youtube.com/watch?v=XWhu_IeEwbM&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java 8 LocalDate Class Introduction | Java Date and Time | Java 8 Date and Time |
import java.time.LocalDate;
public class LocalDateDemo1
{
public static void main(String[] args)
{
/*
* Returns:the current date using the system clock and default
* time-zone, not null
*/
LocalDate localDate = LocalDate.now();
System.out.println(localDate);
System.out.println("Year = " + localDate.getYear());
System.out.println("Month = " + localDate.getMonthValue());
System.out.println 0;"DayOfMonth = " + localDate.getDayOfMonth());
System.out.println("DayOfWeek = " + localDate.getDayOfWeek());
}
}
public class LocalDateDemo1
{
public static void main(String[] args)
{
/*
* Returns:the current date using the system clock and default
* time-zone, not null
*/
LocalDate localDate = LocalDate.now();
System.out.println(localDate);
System.out.println("Year = " + localDate.getYear());
System.out.println("Month = " + localDate.getMonthValue());
System.out.println 0;"DayOfMonth = " + localDate.getDayOfMonth());
System.out.println("DayOfWeek = " + localDate.getDayOfWeek());
}
}
Output
2018-01-03
Year = 2018
Month = 1
DayOfMonth = 3
DayOfWeek = WEDNESDAY
Year = 2018
Month = 1
DayOfMonth = 3
DayOfWeek = WEDNESDAY
LocalDateDemo2.java
import java.time.LocalDate;
public class LocalDateDemo2
{
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, from 1 (January) to
* 12 (December)
*
* dayOfMonth - the day-of-month to represent, from 1 to 31
*
* Returns:the local date, not null
*/
LocalDate localDate = LocalDate.of(2027, 7, 25);
System.out.println(localDate);
}
}
public class LocalDateDemo2
{
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, from 1 (January) to
* 12 (December)
*
* dayOfMonth - the day-of-month to represent, from 1 to 31
*
* Returns:the local date, not null
*/
LocalDate localDate = LocalDate.of(2027, 7, 25);
System.out.println(localDate);
}
}
Output
2027-07-25
LocalDateDemo3.java
import java.time.LocalDate;
public class LocalDateDemo3
{
public static void main(String[] args)
{
/*
* Parameters:
*
* text - the text to parse such as "2007-12-03", not null
*
* Returns:
*
* the parsed local date, not null
*
*/
LocalDate localDate = LocalDate.parse("2007-12-03");
System.out.println(localDate);
}
}
public class LocalDateDemo3
{
public static void main(String[] args)
{
/*
* Parameters:
*
* text - the text to parse such as "2007-12-03", not null
*
* Returns:
*
* the parsed local date, not null
*
*/
LocalDate localDate = LocalDate.parse("2007-12-03");
System.out.println(localDate);
}
}
Output
2007-12-03
Refer:
https://docs.oracle.com/javase/8/docs/api/index.html?java/time/LocalDate.html
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/LocalDateDemo_Intro.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/LocalDateDemo_Intro
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/7d1a1b8046fa2c6f340631d1f5b0f99be87e7675/BasicJava/LocalDateDemo_Intro/?at=master
See also:
No comments:
Post a Comment