dany2855,
function Time(str) {
var objTime = {
init: function(str) {
var arr = str.split(/[\s:-]/);
this.newDate = new Date(Date.UTC(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], 0, 0));
return this;
},
add: function(value, string) {
if (string in this.method) {
return this.setValue(value, this.method[string]);
} else {
throw new Error("Передано неверное значение: " + string);
}
},
method: {
"years": "FullYear",
"months": "Month",
"days": "Date",
"hours": "Hours",
"minutes": "Minutes"
},
setValue: function(value, method) {
this.newDate["setUTC" + method](value + this.newDate["getUTC" + method]());
return this;
},
substract: function(value, string) {
return this.add(-value, string);
},
toString: function() {
return this.newDate.toLocaleString("ru",{timeZone : "UTC"});
},
valueOf: function() {
return +this.newDate
}
};
return objTime.init(str);
};
var str = "2012-01-11 12:35";
var time = new Time(str);
time.add(24, "hours").substract(1, "months").add(3, "days").add(15, "minutes");
alert(time);
alert(+time);