public static Date asDate(Object value) {
        if (value instanceof Date) {
            return (Date) value;
        } else if (value instanceof CharSequence) {
            String date = value.toString().trim();
            try {
                LocalDateTime time;
                if (date.endsWith("Z")) {
                    time = LocalDateTime.parse((CharSequence) value,
                                               DateTimeFormatter.ISO_INSTANT.withZone(Clock.systemUTC().getZone()));
                } else {
                    time = LocalDateTime.parse((CharSequence) value,
                                               DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(Clock.systemUTC().getZone()));
                }
                return new Date(time.atZone(Clock.systemUTC()
                                                 .getZone()).toInstant().toEpochMilli());
            } catch (RuntimeException e) {
                throw new ConfigException(e, "Unable to parse date: " + e.getMessage());
            }
        } else if (value instanceof Long) {
            // Longs are assumed to be java time (millis since epoch).
            return new Date((Long) value);
        } else if (value instanceof Integer) {
            // Integers are assumed to be unix time (seconds since epoch).
            return new Date(((Integer) value).longValue() * 1000L);
        } else {
            throw new IncompatibleValueException("Unable to convert " + value.getClass().getSimpleName() + " to a date");
        }
    }
public static Date asDate ( Object value ) { if ( value instanceof Date ) { return ( Date ) value ; } else if ( value instanceof CharSequence ) { String date = value . toString ( ) . trim ( ) ; try { LocalDateTime time ; if ( date . endsWith ( "Z" ) ) { time = LocalDateTime . parse ( ( CharSequence ) value , DateTimeFormatter . ISO_INSTANT . withZone ( Clock . systemUTC ( ) . getZone ( ) ) ) ; } else { time = LocalDateTime . parse ( ( CharSequence ) value , DateTimeFormatter . ISO_OFFSET_DATE_TIME . withZone ( Clock . systemUTC ( ) . getZone ( ) ) ) ; } return new Date ( time . atZone ( Clock . systemUTC ( ) . getZone ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ; } catch ( RuntimeException e ) { throw new ConfigException ( e , "Unable to parse date: " + e . getMessage ( ) ) ; } } else if ( value instanceof Long ) { return new Date ( ( Long ) value ) ; } else if ( value instanceof Integer ) { return new Date ( ( ( Integer ) value ) . longValue ( ) * 1000L ) ; } else { throw new IncompatibleValueException ( "Unable to convert " + value . getClass ( ) . getSimpleName ( ) + " to a date" ) ; } }
Convert the value to a date.

@param value The value instance.
@return The string value.