示例#1
0
 /**
  * Gets the value of the specified field from this day-of-week as a {@code long}.
  *
  * <p>This queries this day-of-week for the value for the specified field. If it is not possible
  * to return the value, because the field is not supported or for some other reason, an exception
  * is thrown.
  *
  * <p>If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then the value of the
  * day-of-week, from 1 to 7, will be returned. All other {@code ChronoField} instances will throw
  * an {@code UnsupportedTemporalTypeException}.
  *
  * <p>If the field is not a {@code ChronoField}, then the result of this method is obtained by
  * invoking {@code TemporalField.getFrom(TemporalAccessor)} passing {@code this} as the argument.
  * Whether the value can be obtained, and what the value represents, is determined by the field.
  *
  * @param field the field to get, not null
  * @return the value for the field
  * @throws DateTimeException if a value for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 @Override
 public long getLong(TemporalField field) {
   if (field == DAY_OF_WEEK) {
     return getValue();
   } else if (field instanceof ChronoField) {
     throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
   }
   return field.getFrom(this);
 }
示例#2
0
 // -----------------------------------------------------------------------
 @Override
 public long getLong(TemporalField field) {
   if (field instanceof ChronoField) {
     switch ((ChronoField) field) {
       case DAY_OF_WEEK:
         return getDayOfWeek();
       case ALIGNED_DAY_OF_WEEK_IN_MONTH:
         return getAlignedDayOfWeekInMonth();
       case ALIGNED_DAY_OF_WEEK_IN_YEAR:
         return getAlignedDayOfWeekInYear();
       case DAY_OF_MONTH:
         return getDayOfMonth();
       case DAY_OF_YEAR:
         return getDayOfYear();
       case EPOCH_DAY:
         return toEpochDay();
       case ALIGNED_WEEK_OF_MONTH:
         return getAlignedWeekOfMonth();
       case ALIGNED_WEEK_OF_YEAR:
         return getAlignedWeekOfYear();
       case MONTH_OF_YEAR:
         return getMonth();
       case PROLEPTIC_MONTH:
         return getProlepticMonth();
       case YEAR_OF_ERA:
         return getYearOfEra();
       case YEAR:
         return getProlepticYear();
       case ERA:
         return (getProlepticYear() >= 1 ? 1 : 0);
       default:
         break;
     }
     throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
   }
   return field.getFrom(this);
 }