converts a Object to a DateTime Object (Advanced but slower), returns null if invalid string

@param o Object to Convert
@param timeZone
@param defaultValue
@return Date Time Object
15456
public static DateTime toDateAdvanced(Object o, TimeZone timeZone, DateTime defaultValue) {
	if (o instanceof DateTime) return (DateTime) o;
	else if (o instanceof Date) return new DateTimeImpl((Date) o);
	else if (o instanceof Castable) {
	    return ((Castable) o).castToDateTime(defaultValue);
	}
	else if (o instanceof String) return toDateAdvanced(o.toString(), timeZone, defaultValue);
	else if (o instanceof Number) return util.toDateTime(((Number) o).doubleValue());
	else if (o instanceof Calendar) {
	    return new DateTimeImpl((Calendar) o);
	}
	else if (o instanceof ObjectWrap) return toDateAdvanced(((ObjectWrap) o).getEmbededObject(defaultValue), timeZone, defaultValue);
	return defaultValue;
    }
150171
public static Double toDouble(Object o, Double defaultValue) {
	if (o instanceof Double) return (Double) o;
	double dbl = toDoubleValue(o, true, Double.NaN);
	if (Double.isNaN(dbl)) return defaultValue;
	return new Double(dbl);

    }
161134
public static ZonedDateTime convertToZonedDateTime(final String value) {
        val dt = DateTimeUtils.zonedDateTimeOf(value);
        if (dt != null) {
            return dt;
        }
        val lt = DateTimeUtils.localDateTimeOf(value);
        return DateTimeUtils.zonedDateTimeOf(lt.atZone(ZoneOffset.UTC));
    }
701423
public static String changeFormatAndTimeZoneToDefaultUtcFormat(
            String dateFormat, String dateString) {
        return getTimeAsDefaultUtcFormat(changeTimestampToLong(dateFormat,
                dateString));
    }
1099709
public static int toIntValue(Object o, int defaultValue) {

	if (o instanceof Number) return ((Number) o).intValue();
	else if (o instanceof Boolean) return ((Boolean) o).booleanValue() ? 1 : 0;
	else if (o instanceof CharSequence) return toIntValue(o.toString().trim(), defaultValue);
	// else if(o instanceof Clob) return toIntValue(toString(o));
	else if (o instanceof Character) return (int) (((Character) o).charValue());
	else if (o instanceof Castable) {
	    return (int) ((Castable) o).castToDoubleValue(defaultValue);

	}
	else if (o instanceof Date) return (int) new DateTimeImpl((Date) o).castToDoubleValue();
	else if (o instanceof ObjectWrap) return toIntValue(((ObjectWrap) o).getEmbededObject(Integer.valueOf(defaultValue)), defaultValue);

	return defaultValue;
    }
434249
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");
        }
    }
101863
public static DateValue convert(ICalDate date, TimeZone timezone) {
		Calendar c = Calendar.getInstance(timezone);
		c.setTime(date);

		/*
		 * Do not create a "DateValueImpl" object if "date.hasTime() == false".
		 * This interferes with any recurrence iterators the object is passed
		 * into.
		 * 
		 * See: https://github.com/mangstadt/biweekly/issues/47
		 */

		//@formatter:off
		return new DateTimeValueImpl(
			c.get(Calendar.YEAR),
			c.get(Calendar.MONTH)+1,
			c.get(Calendar.DATE),
			c.get(Calendar.HOUR_OF_DAY),
			c.get(Calendar.MINUTE),
			c.get(Calendar.SECOND)
		);
		//@formatter:on
	}
659524
@SuppressWarnings("unchecked")
	public <T> T get(String column, Object defaultValue) {
		Object result = getColumns().get(column);
		return (T)(result != null ? result : defaultValue);
	}
342048
public static long toLongValue(Object o, long defaultValue) {
	if (o instanceof Character) return (((Character) o).charValue());
	else if (o instanceof Boolean) return ((((Boolean) o).booleanValue()) ? 1L : 0L);
	else if (o instanceof Number) return (((Number) o).longValue());
	else if (o instanceof CharSequence) return (long) toDoubleValue(o.toString(), defaultValue);
	else if (o instanceof Castable) {
	    return (long) ((Castable) o).castToDoubleValue(defaultValue);
	}
	else if (o instanceof Character) return (long) (((Character) o).charValue());
	else if (o instanceof ObjectWrap) return toLongValue(((ObjectWrap) o).getEmbededObject(toLong(defaultValue)), defaultValue);

	return defaultValue;
    }
198144
public static ZonedDateTime zonedDateTimeOf(final String value) {
        try {
            return ZonedDateTime.parse(value);
        } catch (final Exception e) {
            return null;
        }
    }
1049246
public Date getTime( String key, Date defaultValue )
        throws MissingResourceException
    {
        try
        {
            return getTime( key );
        }
        catch( MissingResourceException mre )
        {
            return defaultValue;
        }
    }
1374815
def _convert(value, tzto, defaulttz):
    """"""
    if not isinstance(value, datetime):
        raise ValueError('value must be a datetime.datetime object')

    if value.tzinfo is None:
        value = value.replace(tzinfo=defaulttz)

    return value.astimezone(tzto)
133804
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;
	}
379218
def default(self, obj):  # lint-amnesty, pylint: disable=arguments-differ, method-hidden
        

        if isinstance(obj, datetime):
            if obj.tzinfo is None:
                # Localize to UTC naive datetime objects
                obj = UTC.localize(obj)  # pylint: disable=no-value-for-parameter
            else:
                # Convert to UTC datetime objects from other timezones
                obj = obj.astimezone(UTC)
            return obj.isoformat()
        elif isinstance(obj, date):
            return obj.isoformat()

        return super(DateTimeJSONEncoder, self).default(obj)
479613
public Date getDate( String key, Date defaultValue )
        throws MissingResourceException
    {
        try
        {
            return getDate( key );
        }
        catch( MissingResourceException mre )
        {
            return defaultValue;
        }
    }
421092
public static Short toShort(Object o, Short defaultValue) {
	if (o instanceof Short) return (Short) o;
	if (defaultValue != null) return Short.valueOf(toShortValue(o, defaultValue.shortValue()));
	short res = toShortValue(o, Short.MIN_VALUE);
	if (res == Short.MIN_VALUE) return defaultValue;
	return Short.valueOf(res);
    }
824629
@SuppressWarnings("unchecked")
  public <T> T get(String key, Class<T> type, T defaultValue)
  {
    Objects.requireNonNull(key);
    Objects.requireNonNull(type);

    String value = _map.get(key);

    if (value == null) {
      return defaultValue;
    }

    if (type.equals(String.class)) {
      return (T) value;
    }

    T valueType = _converter.convert(type, value);

    if (valueType != null) {
      return valueType;
    }
    else {
      log.warning(L.l("Unexpected type for key={0} type={1} value={2}",
                      key, type, value));
      /*
      throw new ConfigException(L.l("Unexpected type for key={0} type={1} value={2}",
                                    key, type, value));
                                    */
      return defaultValue;
    }
  }