public static ChronoZonedDateTime zonedTime ( final Object target , final ZoneId defaultZoneId ) { Validate . notNull ( target , "Target cannot be null" ) ; Validate . notNull ( defaultZoneId , "ZoneId cannot be null" ) ; if ( target instanceof Instant ) { return ZonedDateTime . ofInstant ( ( Instant ) target , defaultZoneId ) ; } else if ( target instanceof LocalDate ) { return ZonedDateTime . of ( ( LocalDate ) target , LocalTime . MIDNIGHT , defaultZoneId ) ; } else if ( target instanceof LocalDateTime ) { return ZonedDateTime . of ( ( LocalDateTime ) target , defaultZoneId ) ; } else if ( target instanceof LocalTime ) { return ZonedDateTime . of ( LocalDate . now ( ) , ( LocalTime ) target , defaultZoneId ) ; } else if ( target instanceof OffsetDateTime ) { return ( ( OffsetDateTime ) target ) . toZonedDateTime ( ) ; } else if ( target instanceof OffsetTime ) { LocalTime localTime = ( ( OffsetTime ) target ) . toLocalTime ( ) ; return ZonedDateTime . of ( LocalDate . now ( ) , localTime , defaultZoneId ) ; } else if ( target instanceof Year ) { LocalDate localDate = ( ( Year ) target ) . atDay ( 1 ) ; return ZonedDateTime . of ( localDate , LocalTime . MIDNIGHT , defaultZoneId ) ; } else if ( target instanceof YearMonth ) { LocalDate localDate = ( ( YearMonth ) target ) . atDay ( 1 ) ; return ZonedDateTime . of ( localDate , LocalTime . MIDNIGHT , defaultZoneId ) ; } else if ( target instanceof ZonedDateTime ) { return ( ChronoZonedDateTime ) target ; } else { throw new IllegalArgumentException ( "Cannot format object of class \"" + target . getClass ( ) . getName ( ) + "\" as a date" ) ; } }
Creates a Temporal object filling the missing fields of the provided time with default values .