Converting timezone for date using java

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;
}

• What is the ultimate purpose of this method? Dates a represented as milliseconds from the beginning of the epoch. For printing you can choose the timezone of the output using SimpleDateFormat. For persistence you could save the timezone along with the timestamp. – Aleksi Yrttiaho Jul 21 '11 at 8:14
• I get the value from database as timestamp, where i won't have any information of timezone. hence converting the timezone manually – leftrright Jul 21 '11 at 12:02
• NB: Date and time handling isn't very well solved in Java. AFAIK there are several "simplifications" that can lead to problems. If you need reliable time handling have a look at the Joda Time library: joda-time.sourceforge.net . However I can't say if it will be faster than your code. – RoToRa Jul 21 '11 at 13:28
• Where does the Timestamp you are using come from? Is this a java.security.Timestamp? Do you need it it be one of those? – Martijn Jul 23 '11 at 20:44

public static Timestamp convertTimeZone(final Timestamp fromDate, final TimeZone fromTZ, final TimeZone toTZ ){