You're making the false assumption that now.toString()
contains "GMT"
, let's see what is actually given (for me anyway) in IE;
"Tue May 6 13:48:08 UTC+0100 2014"
Notice no GMT, but a UTC.
This means split_result[1]
is undefined, so timezoneOffset
is undefined and hence your error
Unable to get property 'split' of undefined or null reference
This isn't the best way to get the timezone's offset anyway, as we're already provided with a method for just that
date.getTimezoneOffset(); // offset in minutes i.e. for me it is -60
Now you can convert this number to your desired formatting;
var o = date.getTimezoneOffset();
var x = Math.abs(o),
sign = (x === o ? '-' : '+' ),
m = x % 60,
h = (x - m) / 60;
m = (m < 10 ? '0' : '') + m;
h = (h < 10 ? '0' : '') + h;
return sign + h + ':' + m;