/** * Checks if the field type specified is supported by this instant and chronology. This can be * used to avoid exceptions in {@link #get(DateTimeFieldType)}. * * @param type a field type, usually obtained from DateTimeFieldType * @return true if the field type is supported */ public boolean isSupported(DateTimeFieldType type) { if (type == null) { return false; } return type.getField(getChronology()).isSupported(); }
/** * Get the value of one of the fields of a datetime using the chronology of the instant. * * <p>This method uses the chronology of the instant to obtain the value. For example: * * <pre> * DateTime dt = new DateTime(); * int year = dt.get(DateTimeFieldType.year()); * </pre> * * @param type a field type, usually obtained from DateTimeFieldType, not null * @return the value of that field * @throws IllegalArgumentException if the field type is null */ public int get(DateTimeFieldType type) { if (type == null) { throw new IllegalArgumentException("The DateTimeFieldType must not be null"); } return type.getField(getChronology()).get(getMillis()); }