import java.util.TimeZone;
public String getTimeZoneOffSet(String timeZoneID) {
TimeZone tz = TimeZone.getTimeZone(timeZoneID);
int rawOffset = tz.getRawOffset();
int hour = rawOffset / (60 * 60 * 1000);
int minute = Math.abs(rawOffset / (60 * 1000)) % 60;
return hour + ":" + minute;
}
Test:
tc.getTimeZoneOffSet("America/New_York")); This returns Offset for NY -->-5:0
Using Calendar Class
import java.util.Calendar;
public int getOffsetForTimeZone(String timeZoneId) {
int a;
Calendar calendar = new GregorianCalendar();
TimeZone timeZ = calendar.getTimeZone();
timeZ = timeZ.getTimeZone(timeZoneId);
a = (int) ((timeZ.getRawOffset()) * (2.77777778 / 10000000));
return a;
}
public String getTimeZoneOffSet(String timeZoneID) {
TimeZone tz = TimeZone.getTimeZone(timeZoneID);
int rawOffset = tz.getRawOffset();
int hour = rawOffset / (60 * 60 * 1000);
int minute = Math.abs(rawOffset / (60 * 1000)) % 60;
return hour + ":" + minute;
}
Test:
tc.getTimeZoneOffSet("America/New_York")); This returns Offset for NY -->-5:0
Using Calendar Class
import java.util.Calendar;
public int getOffsetForTimeZone(String timeZoneId) {
int a;
Calendar calendar = new GregorianCalendar();
TimeZone timeZ = calendar.getTimeZone();
timeZ = timeZ.getTimeZone(timeZoneId);
a = (int) ((timeZ.getRawOffset()) * (2.77777778 / 10000000));
return a;
}
No comments:
Post a Comment