chinabugotech/hutool · error · IllegalArgumentException

Unknown TimeUnit constant

Error message

Unknown TimeUnit constant

What it means

Error "Unknown TimeUnit constant" thrown in chinabugotech/hutool.

Source

Thrown at hutool-core/src/main/java/cn/hutool/core/date/TemporalUtil.java:73

			return null;
		}
		switch (unit) {
			case NANOSECONDS:
				return ChronoUnit.NANOS;
			case MICROSECONDS:
				return ChronoUnit.MICROS;
			case MILLISECONDS:
				return ChronoUnit.MILLIS;
			case SECONDS:
				return ChronoUnit.SECONDS;
			case MINUTES:
				return ChronoUnit.MINUTES;
			case HOURS:
				return ChronoUnit.HOURS;
			case DAYS:
				return ChronoUnit.DAYS;
			default:
				throw new IllegalArgumentException("Unknown TimeUnit constant");
		}
	}

	/**
	 * 转换 {@link ChronoUnit} 到 {@link TimeUnit}.
	 *
	 * @param unit {@link ChronoUnit},如果为{@code null}返回{@code null}
	 * @return {@link TimeUnit}
	 * @throws IllegalArgumentException 如果{@link TimeUnit}没有对应单位抛出
	 * @since 5.7.16
	 */
	public static TimeUnit toTimeUnit(ChronoUnit unit) throws IllegalArgumentException {
		if (null == unit) {
			return null;
		}
		switch (unit) {
			case NANOS:
				return TimeUnit.NANOSECONDS;

View on GitHub (pinned to 8870454b2a)

Solutions

  1. Use a supported java.util.concurrent.TimeUnit constant (NANOSECONDS through DAYS).
  2. Add a mapping for the TimeUnit you need before calling the conversion.

When it happens

Trigger: Thrown at hutool-core/src/main/java/cn/hutool/core/date/TemporalUtil.java:73 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14). Data as JSON: /api/errors/23a8aea2fe61f8ab. Report an issue: GitHub.