package com.logicbig.example.localdate;
import java.time.*;
public class FromExample {
public static void main (String[] args) {
LocalDate d = LocalDate.from(LocalDateTime.now());
System.out.println(d);
LocalDate d2 = LocalDate.from(ZonedDateTime.now());
System.out.println(d2);
LocalDate d3 = LocalDate.from(OffsetDateTime.now());
System.out.println(d3);
}
}
Output
2017-05-01
2017-05-01
2017-05-01
package com.logicbig.example.localdate;
import java.time.*;
public class FromExample2 {
public static void main (String[] args) {
LocalDate d = LocalDate.from(YearMonth.now());
System.out.println(d);
}
}
Output
Caused by: java.time.DateTimeException: Unable to obtain LocalDate from TemporalAccessor: 2017-05 of type java.time.YearMonth
at java.time.LocalDate.from(LocalDate.java:368)
at com.logicbig.example.localdate.FromExample2.main(FromExample2.java:11)
... 6 more