Sunday, June 1, 2014

Java SE 8 :: Date and Time

Java SE 8 Features - 2
Date and Time in Java SE 8


 
 

As you can find from above, Date and Time in Java 8 replaces shockingly Util.Date, Calendar, TimeZone DateFormat,
All now are replaced with the following range of types:

 
 

To make it more clear let take the following example to get to know more about the syntax of the date and time in Java SE 8.

Let’s say the date is 1st June 2014 15:30.
LocalDate localDate = LocalDate.of(2014,Month.June,1);
LocalTime localTime = LocalTime.of(15, 30);
LocalDateTime localDateTime = LocalDateTime.of(2014,Month.June,1,15,30);

Sample of new Date methods:
-          To find if this year is leap or not : Date.isLeapYear();
-          localDate.minusMonth(3).plusDays(10); on previous example will generate 10/3/2014.
-          localTime.now(),localDate.now(),localDateTime.now(); to get current Date.
-          And many others: D.

Local Date Adjuster:
You may adjust the date with some constant values as follows
localDate = localDate.with(TemporalAdjuster.LastDateOfMonth);
Will generate 30/6/2014.

Happy News for developers deals with Saudi companies:
Chronology:
Which is other types of Calendar, and now Hijri calendar is supported.

No comments:

Post a Comment