public Date convertToDate ( long millis , TimeZone tz ) { // no adjustments for the inifity hack values if ( millis <= PGStatement . DATE_NEGATIVE_INFINITY || millis >= PGStatement . DATE_POSITIVE_INFINITY ) { return new Date ( millis ) ; } if ( tz == null ) { tz = getDefaultTz ( ) ; } if ( isSimpleTimeZone ( tz . getID ( ) ) ) { // Truncate to 00:00 of the day. // Suppose the input date is 7 Jan 15:40 GMT+02:00 (that is 13:40 UTC) // We want it to become 7 Jan 00:00 GMT+02:00 // 1) Make sure millis becomes 15:40 in UTC, so add offset int offset = tz . getRawOffset ( ) ; millis += offset ; // 2) Truncate hours, minutes, etc. Day is always 86400 seconds, no matter what leap seconds // are millis = millis / ONEDAY * ONEDAY ; // 2) Now millis is 7 Jan 00:00 UTC, however we need that in GMT+02:00, so subtract some // offset millis -= offset ; // Now we have brand-new 7 Jan 00:00 GMT+02:00 return new Date ( millis ) ; } Calendar cal = calendarWithUserTz ; cal . setTimeZone ( tz ) ; cal . setTimeInMillis ( millis ) ; cal . set ( Calendar . HOUR_OF_DAY , 0 ) ; cal . set ( Calendar . MINUTE , 0 ) ; cal . set ( Calendar . SECOND , 0 ) ; cal . set ( Calendar . MILLISECOND , 0 ) ; return new Date ( cal . getTimeInMillis ( ) ) ; }
Extracts the date part from a timestamp .