Returns the SQL Date object matching the given bytes with {@link Oid#DATE}.

@param tz The timezone used.
@param bytes The binary encoded date value.
@return The parsed date object.
@throws PSQLException If binary format could not be parsed.
540935
public Date toDateBin(TimeZone tz, byte[] bytes) throws PSQLException {
    if (bytes.length != 4) {
      throw new PSQLException(GT.tr("Unsupported binary encoding of {0}.", "date"),
          PSQLState.BAD_DATETIME_FORMAT);
    }
    int days = ByteConverter.int4(bytes, 0);
    if (tz == null) {
      tz = getDefaultTz();
    }
    long secs = toJavaSecs(days * 86400L);
    long millis = secs * 1000L;

    if (millis <= PGStatement.DATE_NEGATIVE_SMALLER_INFINITY) {
      millis = PGStatement.DATE_NEGATIVE_INFINITY;
    } else if (millis >= PGStatement.DATE_POSITIVE_SMALLER_INFINITY) {
      millis = PGStatement.DATE_POSITIVE_INFINITY;
    } else {
      // Here be dragons: backend did not provide us the timezone, so we guess the actual point in
      // time

      millis = guessTimestamp(millis, tz);
    }
    return new Date(millis);
  }
681078
public static <T extends BaseBo> T fromBytes(byte[] bytes, Class<T> clazz) {
        return fromBytes(bytes, clazz, null);
    }
325945
public int setBytes(final long pos, byte[] bytes) throws SQLException {
        if (bytes == null) {
            throw new IllegalArgumentException("No byte to be set");
        } // end of if

        return setBytes(pos, bytes, 0, bytes.length);
    }
534138
@Override
    public byte[] getBytes(int columnIndex) throws SQLException {
        checkColumnBounds(columnIndex);
        try {
            if (table.getColumnType(columnIndex - 1) == VoltType.STRING)
                return table.getStringAsBytes(columnIndex - 1);
            else if (table.getColumnType(columnIndex - 1) == VoltType.VARBINARY)
                return table.getVarbinary(columnIndex - 1);
            else
                throw SQLError.get(SQLError.CONVERSION_NOT_FOUND,
                        table.getColumnType(columnIndex - 1), "byte[]");
        } catch (SQLException x) {
            throw x;
        } catch (Exception x) {
            throw SQLError.get(x);
        }
    }
443167
public static String dateSub(long ts, int days, TimeZone tz) {
		ZoneId zoneId = tz.toZoneId();
		Instant instant = Instant.ofEpochMilli(ts);
		ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, zoneId);
		long resultTs = zdt.minusDays(days).toInstant().toEpochMilli();
		return dateFormat(resultTs, DATE_FORMAT_STRING, tz);
	}
280232
def date_struct(year, month, day, tz = "UTC"):
    
    ymdtz = (year, month, day, tz)
    if None in ymdtz:
        #logger.debug("a year, month, day or tz value was empty: %s" % str(ymdtz))
        return None # return early if we have a bad value
    try:
        return time.strptime("%s-%s-%s %s" % ymdtz,  "%Y-%m-%d %Z")
    except(TypeError, ValueError):
        #logger.debug("date failed to convert: %s" % str(ymdtz))
        pass
1164049
@Override
  public final Date fromIso8601DateTimeSecNoTz(final String pDateStr,
    final Map<String, Object> pAddParam) throws Exception {
    return this.dateTimeSecNoTzFormatIso8601.parse(pDateStr);
  }
577196
public static String isoDateTime(final Date val, final TimeZone tz) {
    synchronized (isoDateTimeTZFormat) {
      isoDateTimeTZFormat.setTimeZone(tz);
      return isoDateTimeTZFormat.format(val);
    }
  }
620210
public static Timestamp parseTimestamp(final String date, final String format, final TimeZone timeZone) {
        if (N.isNullOrEmpty(date) || (date.length() == 4 && "null".equalsIgnoreCase(date))) {
            return null;
        }

        return createTimestamp(parse(date, format, timeZone));
    }
1127729
private Date toDate(final String pStringDate) {

        // weird manipulation to parse the date... remove ':' from the timezone
        // before: 2011-07-12T22:42:40.000+02:00
        // after: 2011-07-12T22:42:40.000+0200
        final StringBuilder _date = new StringBuilder();
        _date.append(pStringDate.substring(0, pStringDate.length() - 3));
        _date.append(pStringDate.substring(pStringDate.length() - 2));
        try {
            return new SimpleDateFormat(RFC_339_DATE_FORMAT).parse(_date.toString());
        } catch (final ParseException e) {
            throw new IllegalArgumentException(
                    "The given spreadsheet ListEntry usercrashdate field value is malformed", e);
        }
    }
568726
@Override
  public final Date fromIso8601DateNoTz(final String pDateStr,
    final Map<String, Object> pAddParam) throws Exception {
    return this.dateNoTzFormatIso8601.parse(pDateStr);
  }
407399
public static String dateFormat(String dateStr, String fromFormat, String toFormat, TimeZone tz) {
		SimpleDateFormat fromFormatter = FORMATTER_CACHE.get(fromFormat);
		fromFormatter.setTimeZone(tz);
		SimpleDateFormat toFormatter = FORMATTER_CACHE.get(toFormat);
		toFormatter.setTimeZone(tz);
		try {
			return toFormatter.format(fromFormatter.parse(dateStr));
		} catch (ParseException e) {
			LOG.error("Exception when formatting: '" + dateStr +
				"' from: '" + fromFormat + "' to: '" + toFormat + "'", e);
			return null;
		}
	}
853316
@Override
  public final String toIso8601DateTimeNoTz(final Date pDate,
    final Map<String, Object> pAddParam) throws Exception {
    return this.dateTimeNoTzFormatIso8601.format(pDate);
  }
157656
def _utc(dt, source, field_name):
    
    if dt is None:
        raise dbt.exceptions.raise_database_error(
            "Expected a non-null value when querying field '{}' of table "
            " {} but received value 'null' instead".format(
                field_name,
                source))

    elif not hasattr(dt, 'tzinfo'):
        raise dbt.exceptions.raise_database_error(
            "Expected a timestamp value when querying field '{}' of table "
            "{} but received value of type '{}' instead".format(
                field_name,
                source,
                type(dt).__name__))

    elif dt.tzinfo:
        return dt.astimezone(pytz.UTC)
    else:
        return dt.replace(tzinfo=pytz.UTC)
1033372
public static <T> T withBytes(byte[] bytes, Class<T> c) {
        try {
            return jsonMapper.readValue(bytes, c);
        } catch (Exception e) {
            return JMExceptionManager.handleExceptionAndReturnNull(log, e,
                    "withBytes", new String(bytes));
        }
    }
1366841
def from_timestamp(
    timestamp, tz=UTC  # type: Union[int, float]  # type: Union[str, _Timezone]
):  # type: (...) -> DateTime
    
    dt = _datetime.datetime.utcfromtimestamp(timestamp)

    dt = datetime(
        dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond
    )

    if tz is not UTC or tz != "UTC":
        dt = dt.in_timezone(tz)

    return dt
1225262
static public long getDateTime(String s, String format, TimeZone tz)
    {
        long ret = 0L;
        SimpleDateFormat df = null;

        try
        {
            if(s != null && s.length() > 0)
            {
                df = formatPool.getFormat(format);
                df.setTimeZone(tz);
                Date dt = df.parse(s);
                ret = dt.getTime();
            }
        }
        catch(Exception e)
        {
        }

        if(df != null)
            formatPool.release(df);

        return ret;
    }