I navigation across Java 8 Date and Time new API and i couldn't go any further and i cannot find any good resource in the web i hope you be kindle with this question.
My simple source code is
final LocalDate date = LocalDate.now();
date.get(TemporalField field)
And i get the source code and i see.
public int get(TemporalField field)
Gets the value of the specified field from this date as an int.
My question is how i can get a TemporalField or which is the easiest way to get this code to work..
final int value = date.get(????);
This works thanks to JB Nizet
date.get(java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH);
API.
http://docs.oracle.com/javase/8/docs/api/java/time/temporal/ChronoField.html
There are a number of ways to get instances of TemporalField
.
Firstly, the enum ChronoField
implements TemporalField
and contains various constants.
ChronoField.ALIGNED_WEEK_OF_YEAR;
Secondly, the classes IsoFields
and JulianFields
contain static TemporalField
objects.
IsoFields.QUARTER_OF_YEAR;
JulianFields.JULIAN_DAY;
Thirdly, the class WeekFields
contains static TemporalField
objects and methods to create TemporalField
objects based off WeekFields.
WeekFields.WEEK_BASED_YEARS;
WeekFields.SUNDAY_START.weekOfMonth();
The Javadoc of TemporalField says, right there:
"The most commonly used units are defined in ChronoField. Further fields are supplied in IsoFields, WeekFields and JulianFields. Fields can also be written by application code by implementing this interface."
Pick what you want to get out from those fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With