Issues with the Existing Date/Time APIs
1. Thread Safefty:- develpoers have to deal with concurrency issues.new date and time api in java 8 are immutable and thread safe and thus taking concurrency headache away from developers.
2. API Design and Ease of Understanding: good utility methods in new API
3. Zoned Date and Time Functinality is added.
4. The format that I have used in my project is basically a user defined format
String userdefinedDate=localdate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"));
System.out.println(userdefinedDate);
System.out.println(userdefinedDate);
====================================================================
Study Link
Working With LocalDate
LocalDate localDate = LocalDate.now();
LocalDate.of(2015, 02, 20);
LocalDate tomorrow = LocalDate.now().plusDays(1);
DayOfWeek sunday = LocalDate.parse("2016-06-12").getDayOfWeek()
package com.sandy;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
public class TestClass2 {
public static void main(String[] args) {
LocalDate localdate=LocalDate.now();
System.out.println(localdate);
System.out.println(localdate.getDayOfWeek());
System.out.println(localdate.getMonth());
System.out.println(localdate.getYear());
System.out.println("==========================");
System.out.println(localdate.getDayOfMonth()+"."+ localdate.getMonthValue() +"."+ localdate.getYear()+" ");
System.out.println(localdate.getDayOfMonth());
/*
* String
* formatterDate=localdate.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.
* LONG)); System.out.println(formatterDate);
*/
String userdefinedDate=localdate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"));
System.out.println(userdefinedDate);
}
}
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
public class TestClass2 {
public static void main(String[] args) {
LocalDate localdate=LocalDate.now();
System.out.println(localdate);
System.out.println(localdate.getDayOfWeek());
System.out.println(localdate.getMonth());
System.out.println(localdate.getYear());
System.out.println("==========================");
System.out.println(localdate.getDayOfMonth()+"."+ localdate.getMonthValue() +"."+ localdate.getYear()+" ");
System.out.println(localdate.getDayOfMonth());
/*
* String
* formatterDate=localdate.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.
* LONG)); System.out.println(formatterDate);
*/
String userdefinedDate=localdate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"));
System.out.println(userdefinedDate);
}
}
Comments
Post a Comment