Creates a date from the equivalent long value. This conversion
takes account of the time zone.

@param date date expressed as a long integer
@return new Date instance
431282
public static Date getDateFromLong(long date)
   {
      TimeZone tz = TimeZone.getDefault();
      return (new Date(date - tz.getRawOffset()));
   }
320992
public static XMLGregorianCalendar timeStamp(Date date) {
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		return xmlDatatypeFactory.newXMLGregorianCalendar(gc);
	}
1348828
public static Timestamp toTimestamp(final Date date)
	{
		final Calendar cal = new GregorianCalendar();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);

		return new Timestamp(cal.getTime().getTime());
	}
27072
public static LocalDateTime dateToLocalDateTime(Date date) {

        if (date == null) {
            return null;
        }
        return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
    }
1187858
public static final Date utc2date(Long time) {

        // don't accept negative values
        if (time == null || time < 0) return null;
        
        // add the timezone offset
        time += timezoneOffsetMillis(new Date(time));

        return new Date(time);
    }
336065
public static PlainDate from(GregorianDate date) {

        if (date instanceof PlainDate) {
            return (PlainDate) date;
        } else {
            return PlainDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth());
        }

    }
113096
public Date getValueAsDate(final TimeZone tz) {
        long time = ((Date) value).getTime();
        long offset;
        if(tz == null) {
            offset = TimeZone.getDefault().getRawOffset();
        } else {
            offset = tz.getRawOffset();
        }
        
        return new Date(time - offset);
    }
742754
public Date toDate(Object date) {

        Date d = null;
        if (null != date) {
            if (date instanceof Date) {
                d = (Date)date;
            } else if (date instanceof Long) {
                d = new Date(((Long)date).longValue());
            } else {
                try {
                    long l = Long.parseLong(date.toString());
                    d = new Date(l);
                } catch (Exception e) {
                    // do nothing, just let d remain null
                }
            }
        }
        return d;
    }
57247
public static String formatDate(final Date date) {
        
        ArgUtils.notNull(date, "date");
        
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        format.setTimeZone(TimeZone.getTimeZone("GMT-00:00"));
        return format.format(date);
        
    }
179247
public static Date parseDate(final String date) {

        /*
            IE9 sends a superflous lenght parameter after date in the
            If-Modified-Since header, which needs to be stripped before
            parsing.

         */

        final int semicolonIndex = date.indexOf(';');
        final String trimmedDate = semicolonIndex >= 0 ? date.substring(0, semicolonIndex) : date;

        ParsePosition pp = new ParsePosition(0);
        SimpleDateFormat dateFormat = RFC1123_PATTERN_FORMAT.get();
        dateFormat.setTimeZone(GMT_ZONE);
        Date val = dateFormat.parse(trimmedDate, pp);
        if (val != null && pp.getIndex() == trimmedDate.length()) {
            return val;
        }

        pp = new ParsePosition(0);
        dateFormat = new SimpleDateFormat(RFC1036_PATTERN, LOCALE_US);
        dateFormat.setTimeZone(GMT_ZONE);
        val = dateFormat.parse(trimmedDate, pp);
        if (val != null && pp.getIndex() == trimmedDate.length()) {
            return val;
        }

        pp = new ParsePosition(0);
        dateFormat = new SimpleDateFormat(ASCITIME_PATTERN, LOCALE_US);
        dateFormat.setTimeZone(GMT_ZONE);
        val = dateFormat.parse(trimmedDate, pp);
        if (val != null && pp.getIndex() == trimmedDate.length()) {
            return val;
        }

        pp = new ParsePosition(0);
        dateFormat = new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
        dateFormat.setTimeZone(GMT_ZONE);
        val = dateFormat.parse(trimmedDate, pp);
        if (val != null && pp.getIndex() == trimmedDate.length()) {
            return val;
        }

        return null;
    }
159420
private Date convertDate(final Object data) {
		if (data == null) {
			return null;
		} else if (data instanceof Date) {
			return (Date) data;
		} else if (data instanceof Long) {
			return new Date((Long) data);
		} else if (data instanceof Calendar) {
			return ((Calendar) data).getTime();
		} else if (data instanceof String) {
			try {
				SimpleDateFormat sdf = new SimpleDateFormat(INTERNAL_DATE_FORMAT);
				sdf.setLenient(lenient);
				return sdf.parse((String) data);
			} catch (ParseException e) {
				throw new SystemException("Could not convert String data [" + data + "] to a date.");
			}
		}

		throw new SystemException("Cannot convert data type " + data.getClass() + " to a date.");
	}
995956
public static String dateToString(Date date) {
        final TimeZone utc = TimeZone.getTimeZone("UTC");

        SimpleDateFormat tformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
        tformat.setTimeZone(utc);
        return tformat.format(date);
    }
300162
public static String formatDate(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat(TIMESTAMP_FORMAT);
        return formatter.format(date);
    }
1087299
@SuppressWarnings("deprecation")
	private Date setHourToZero(Date in) {
		final Date d = new Date(in.getTime());
		d.setHours(0);
		d.setMinutes(0);
		d.setSeconds(0);
		// a trick to set milliseconds to zero
		long t = d.getTime() / 1000;
		t = t * 1000;
		return new Date(t);
	}
907739
public String dateToString(Date date)
    {
        if (date == null)
            return "";
        try {
            return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(date);
        } catch (Exception ex) {
        }
        return "";
    }
4773
public static long parse(String date, String time) {
		return parseDate(date) + parseTime(time) + timeZoneOffset;
	}
551504
public static String dateToString(final Date date) {

        String result;
        if (date == null) {
            result = "";
        } else {
            result = Z_DATE_FORMAT.format(date);
        }
        return result;
    }