Monday, February 1, 2016

How to find timeZone offset between two timezones in IBM BPM

Many a time during our development, we need to calculate the time zone offset (time difference) between two different time zones during the date manipulations. In this Post, I would like provide a simple function which will give the time Difference between two Time Zones.


function getTimeZoneOffset(zone1,zone2){
    var date=new TWDate();
    var dateString=date.format("MM/dd/yyyy HH:mm.ss");
    var Zone1Date=new TWDate();
    var Zone2Date=new TWDate();
    Zone1Date.parse(dateString, "MM/dd/yyyy HH:mm.ss", zone1);
    Zone2Date.parse(dateString, "MM/dd/yyyy HH:mm.ss", zone2);
    var offset= Math.ceil((Zone1Date.getTime()-Zone2Date.getTime())/(60*60));
    return offset;
}


Note: The above method ve offset in hours

This method can be used as below;

var offSet1=getTimeZoneOffset("EST","GMT") 
var offSet2=getTimeZoneOffset("GMT","EST")

Output:
offset1 is evaluated to '5' 
offset2 is evaluated to '-5'  



No comments:

Post a Comment