public static ZonedDateTime toNullableDateTime ( Object value ) { if ( value == null ) return null ; if ( value instanceof ZonedDateTime ) return ( ZonedDateTime ) value ; if ( value instanceof Calendar ) { Calendar calendar = ( Calendar ) value ; return ZonedDateTime . ofInstant ( calendar . toInstant ( ) , calendar . getTimeZone ( ) . toZoneId ( ) ) ; } if ( value instanceof Date ) return ZonedDateTime . ofInstant ( ( ( Date ) value ) . toInstant ( ) , ZoneId . systemDefault ( ) ) ; if ( value instanceof LocalDate ) return ZonedDateTime . of ( ( LocalDate ) value , LocalTime . of ( 0 , 0 ) , ZoneId . systemDefault ( ) ) ; if ( value instanceof LocalDateTime ) return ZonedDateTime . of ( ( LocalDateTime ) value , ZoneId . systemDefault ( ) ) ; if ( value instanceof Integer ) return millisToDateTime ( ( int ) value ) ; if ( value instanceof Short ) return millisToDateTime ( ( short ) value ) ; if ( value instanceof Long ) return millisToDateTime ( ( long ) value ) ; if ( value instanceof Float ) return millisToDateTime ( ( long ) ( ( float ) value ) ) ; if ( value instanceof Double ) return millisToDateTime ( ( long ) ( ( double ) value ) ) ; if ( value instanceof Duration ) return millisToDateTime ( ( ( Duration ) value ) . toMillis ( ) ) ; if ( value instanceof String ) { try { return ZonedDateTime . parse ( ( String ) value , DateTimeFormatter . ISO_OFFSET_DATE_TIME ) ; } catch ( DateTimeParseException ex ) { } try { return ZonedDateTime . of ( LocalDateTime . parse ( ( String ) value , simpleDateTimeFormatter ) , ZoneId . systemDefault ( ) ) ; } catch ( DateTimeParseException ex ) { } try { return ZonedDateTime . of ( LocalDate . parse ( ( String ) value , simpleDateFormatter ) , LocalTime . of ( 0 , 0 ) , ZoneId . systemDefault ( ) ) ; } catch ( DateTimeParseException ex ) { } } return null ; }
Converts value into Date or returns null when conversion is not possible .