You can't "set" the timezone offset, it's a read only property that is based on system settings.
You can generate time and date values for any timezone offset by simply adding the client timezone offset, then adding whatever offset you want (note that javascript Date object's timezone offset has an opposite sense to the usual value, so you add both rather than subtracting one and adding the other).
e.g.
// Provide offsetInMintes to add to UTC to get required time,
// e.g. Nepal Standard Time is UTC +05:45 -> +345 minutes
function generateOffsetTime(offsetInMinutes) {
function z(n){return (n<10? '0' : '') + n;}
var d = new Date();
d.setMinutes(d.getMinutes() + d.getTimezoneOffset() + offsetInMinutes);
return [z(d.getHours()),z(d.getMinutes()),z(d.getSeconds())].join(':');
}
alert('The time in Nepal is ' + generateOffsetTime(345));
Edit
You could add your own methods to Date.prototype:
Date.prototype.setOffset = function(offsetInMinutes, offsetName) {
this._offsetInMinutes = offsetInMinutes;
this._offsetName = offsetName;
};
Date.prototype.getOffsetFullDate = (function() {
var months = ('January February March April May June July ' +
'August September October November December').split(' ');
var days = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split(' ');
return function() {
var d = new Date(+this);
d.setMinutes(d.getMinutes() + d.getTimezoneOffset() + this._offsetInMinutes);
return days[d.getDay()] + ' ' + d.getDate() + ' ' + months[d.getMonth()] +
', ' + this.getFullYear();
}
}());
Date.prototype.getOffsetTime = (function() {
function z(n){return (n<10? '0' : '') + n;}
return function() {
var d = new Date(+this);
d.setMinutes(d.getMinutes() + d.getTimezoneOffset() + this._offsetInMinutes);
return z(d.getHours()) + ':' + z(d.getMinutes()) + ':' +
z(d.getSeconds()) + ' ' + this._offsetName;
}
}());
var d = new Date();
d.setOffset(345, 'NST')
console.log(d.getOffsetFullDate() + ' ' + d.getOffsetTime());
Note that this keeps the date object's original timevalue, it adjusts values as they are retrieved so the timezone can be changed to get different values for the same date object, so you could continue with:
d.setOffset(600, 'AEST');
console.log(d.getOffsetFullDate() + ' ' + d.getOffsetTime());
d.setOffset(630, 'LHI');
console.log(d.getOffsetFullDate() + ' ' + d.getOffsetTime());
But I still think it's better to build your own date constructor that leverages the built in Date rather than extends it.