You are correct. It should be getYear() and not getDayOfYear(). This will be added to the book’s errata.
For better or worse I used a more verbose approach to calculate the current date to illustrate the methods available. LocalDate.now() is shorter and can be used. Knowing about these methods allows you to easily calculate a future date where one of the “of” methods parameter is modified. Similar results can be obtained using a “plus” method.
The new data and time API provides a lot of flexibility in how temporal values can be created. At the same time, this flexibility can be confusing as to which method is best.
Campbell Ritchie wrote:Nice to see you again, Darryl
Thank you, Campbell. I've been doing some stuff at home with JDBC, Swing and Java 8 features and coded convoluted parse/format conversions between SQL Date and LocalDate before I discovered the new toLocalDate() and valueOf(LocalDate) methods. I do wish the latter had been designed to return null for a null argument instead of throwing a NPE though.
Joined: Oct 13, 2005
I haven't looked at that method, but I think I might have thrown an NPE, too.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Java 8 New Features - creating the current date