I have written this method for converting a date time zone. How do i reduce the execution time of this method further.
public static Timestamp convertTimeZone(final Timestamp fromDate, final TimeZone fromTZ, final TimeZone toTZ ){
Long timeInDate = fromDate.getTime() ;
int fromOffset = fromTZ.getOffset(timeInDate);
int toOffset = toTZ.getOffset(timeInDate);
Timestamp dateStamp = new Timestamp(fromDate.getTime());
if( fromOffset >= 0){
int diff = 0;
if( toOffset > 0){
diff = ( fromOffset - toOffset);
}else{
diff = ( fromOffset + Math.abs(toOffset));
}
long date = fromDate.getTime() - diff;
dateStamp.setTime( date );
}else{
int diff = 0;
if( toOffset > 0){
diff = ( Math.abs( fromOffset) + toOffset);
}else{
diff = ( Math.abs( fromOffset) - Math.abs(toOffset));
}
long date = fromDate.getTime() + diff;
dateStamp.setTime( date );
}
return dateStamp;
}
Timestamp
you are using come from? Is this ajava.security.Timestamp
? Do you need it it be one of those? \$\endgroup\$