/** * Calculate the date value (in the default timezone) from a given time in * milliseconds in UTC. * * @param ms the milliseconds * @return the date value */ public static long dateValueFromDate(long ms) { Calendar cal = getCalendar(); synchronized (cal) { cal.clear(); cal.setTimeInMillis(ms); return dateValueFromCalendar(cal); } }
/** * Convert the date using the specified calendar. * * @param x the date * @param calendar the calendar * @return the date */ public static ValueDate convertDate(Date x, Calendar calendar) { if (calendar == null) { throw DbException.getInvalidValueException("calendar", null); } Calendar cal = (Calendar) calendar.clone(); cal.setTimeInMillis(x.getTime()); long dateValue = dateValueFromCalendar(cal); return ValueDate.fromDateValue(dateValue); }
/** * Convert the timestamp using the specified calendar. * * @param x the time * @param calendar the calendar * @return the timestamp */ public static ValueTimestamp convertTimestamp(Timestamp x, Calendar calendar) { if (calendar == null) { throw DbException.getInvalidValueException("calendar", null); } Calendar cal = (Calendar) calendar.clone(); cal.setTimeInMillis(x.getTime()); long dateValue = dateValueFromCalendar(cal); long nanos = nanosFromCalendar(cal); nanos += x.getNanos() % 1000000; return ValueTimestamp.fromDateValueAndNanos(dateValue, nanos); }