public static Date timeZoneConversion(Date date, TimeZone source, TimeZone target) { if( !source.equals(target) ) { // creation of a calendar for the date in the SOURCE tz DateTime.TGregorianCalendar calSource=DateTime.getCalendar(); // creation of a calendar for the same 'absolute time' in TARGET tz DateTime.TGregorianCalendar calTarget=DateTime.getCalendar(); try { calSource.setTimeZone(source); calSource.setTime(date); // offset to convert : source -> GMT int zoneOffsetSource=-calSource.get(Calendar.ZONE_OFFSET); int dstOffsetSource=-calSource.get(Calendar.DST_OFFSET); calTarget.setTimeZone(target); calTarget.setMillis(calSource.getMillis()); // offset to convert : GMT -> XSP server tz int zoneOffsetTarget=calTarget.get(Calendar.ZONE_OFFSET); int dstOffsetTarget=calTarget.get(Calendar.DST_OFFSET); long totalOffset=((long)zoneOffsetSource)+dstOffsetSource+zoneOffsetTarget+dstOffsetTarget; // obtain a new date in xsp server tz date=new Date(date.getTime()+totalOffset); } finally { DateTime.recycleCalendar(calSource); DateTime.recycleCalendar(calTarget); } } return date; }
public static Date timeZoneConversion(Date date, TimeZone source, TimeZone target) { if( !source.equals(target) ) { // creation of a calendar for the date in the SOURCE tz DateTime.TGregorianCalendar calSource=DateTime.getCalendar(); // creation of a calendar for the same 'absolute time' in TARGET tz DateTime.TGregorianCalendar calTarget=DateTime.getCalendar(); try { calSource.setTimeZone(source); calSource.setTime(date); // offset to convert : source -> GMT int zoneOffsetSource=-calSource.get(Calendar.ZONE_OFFSET); int dstOffsetSource=-calSource.get(Calendar.DST_OFFSET); calTarget.setTimeZone(target); calTarget.setMillis(calSource.getMillis()); // offset to convert : GMT -> XSP server tz int zoneOffsetTarget=calTarget.get(Calendar.ZONE_OFFSET); int dstOffsetTarget=calTarget.get(Calendar.DST_OFFSET); long totalOffset=((long)zoneOffsetSource)+dstOffsetSource+zoneOffsetTarget+dstOffsetTarget; // obtain a new date in xsp server tz date=new Date(date.getTime()+totalOffset); } finally { DateTime.recycleCalendar(calSource); DateTime.recycleCalendar(calTarget); } } return date; }
public static java.sql.Timestamp timeZoneTimestampConversion(java.sql.Timestamp date, TimeZone source, TimeZone target) { if( !source.equals(target) ) { // creation of a calendar for the date in the SOURCE tz DateTime.TGregorianCalendar calSource=DateTime.getCalendar(); // creation of a calendar for the same 'absolute time' in TARGET tz DateTime.TGregorianCalendar calTarget=DateTime.getCalendar(); try { calSource.setTimeZone(source); calSource.setTime(date); // offset to convert : source -> GMT int zoneOffsetSource=-calSource.get(Calendar.ZONE_OFFSET); int dstOffsetSource=-calSource.get(Calendar.DST_OFFSET); calTarget.setTimeZone(target); calTarget.setMillis(calSource.getMillis()); // offset to convert : GMT -> XSP server tz int zoneOffsetTarget=calTarget.get(Calendar.ZONE_OFFSET); int dstOffsetTarget=calTarget.get(Calendar.DST_OFFSET); long totalOffset=((long)zoneOffsetSource)+dstOffsetSource+zoneOffsetTarget+dstOffsetTarget; // obtain a new date in xsp server tz date=new java.sql.Timestamp(date.getTime()+totalOffset); } finally { DateTime.recycleCalendar(calSource); DateTime.recycleCalendar(calTarget); } } return date; }
gregorianCalendar.set(year,month-1,day,hour,minute,second); gregorianCalendar.set(GregorianCalendar.MILLISECOND,0); long xmlDate = gregorianCalendar.getMillis();
calTarget.setMillis(calSource.getMillis());
calTarget.setMillis(calSource.getMillis());
calTarget.setMillis(calSource.getMillis());
calTarget.setMillis(calSource.getMillis());
public static java.sql.Timestamp timeZoneTimestampConversion(java.sql.Timestamp date, TimeZone source, TimeZone target) { if( !source.equals(target) ) { // creation of a calendar for the date in the SOURCE tz DateTime.TGregorianCalendar calSource=DateTime.getCalendar(); // creation of a calendar for the same 'absolute time' in TARGET tz DateTime.TGregorianCalendar calTarget=DateTime.getCalendar(); try { calSource.setTimeZone(source); calSource.setTime(date); // offset to convert : source -> GMT int zoneOffsetSource=-calSource.get(Calendar.ZONE_OFFSET); int dstOffsetSource=-calSource.get(Calendar.DST_OFFSET); calTarget.setTimeZone(target); calTarget.setMillis(calSource.getMillis()); // offset to convert : GMT -> XSP server tz int zoneOffsetTarget=calTarget.get(Calendar.ZONE_OFFSET); int dstOffsetTarget=calTarget.get(Calendar.DST_OFFSET); long totalOffset=((long)zoneOffsetSource)+dstOffsetSource+zoneOffsetTarget+dstOffsetTarget; // obtain a new date in xsp server tz date=new java.sql.Timestamp(date.getTime()+totalOffset); } finally { DateTime.recycleCalendar(calSource); DateTime.recycleCalendar(calTarget); } } return date; }
/** * * @param y The year (already adjusted, no need to add 1900 or 2000) */ public static final long createDateAsLong( int y, int m, int d, int h, int n, int s, int ms ) { TGregorianCalendar gregorianCalendar = getCalendar(); try { gregorianCalendar.set(y,m-1,d,h,n,s); gregorianCalendar.set(GregorianCalendar.MILLISECOND,ms); return gregorianCalendar.getMillis(); } finally { recycleCalendar(gregorianCalendar); } } /**
/** * * @param y The year (already adjusted, no need to add 1900 or 2000) */ public static final long createDateAsLong( int y, int m, int d, int h, int n, int s ) { TGregorianCalendar gregorianCalendar = getCalendar(); try { gregorianCalendar.set(y,m-1,d,h,n,s); gregorianCalendar.set(GregorianCalendar.MILLISECOND,0); return gregorianCalendar.getMillis(); } finally { recycleCalendar(gregorianCalendar); } } public String toString() {
/** * * @param y The year (already adjusted, no need to add 1900 or 2000) */ public static final long createDateAsLong( int y, int m, int d, int h, int n, int s ) { TGregorianCalendar gregorianCalendar = getCalendar(); try { gregorianCalendar.set(y,m-1,d,h,n,s); gregorianCalendar.set(GregorianCalendar.MILLISECOND,0); return gregorianCalendar.getMillis(); } finally { recycleCalendar(gregorianCalendar); } } public String toString() {
/** * * @param y The year (already adjusted, no need to add 1900 or 2000) */ public static final long createDateAsLong( int y, int m, int d, int h, int n, int s, int ms ) { TGregorianCalendar gregorianCalendar = getCalendar(); try { gregorianCalendar.set(y,m-1,d,h,n,s); gregorianCalendar.set(GregorianCalendar.MILLISECOND,ms); return gregorianCalendar.getMillis(); } finally { recycleCalendar(gregorianCalendar); } } /**