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() {
var year = this.newDate.getUTCFullYear();
var month = this.newDate.toLocaleString("ru",{timeZone : "UTC",month: '2-digit'});
var day = this.newDate.toLocaleString("ru",{timeZone : "UTC",day: '2-digit'});
var time = this.newDate.toLocaleString("ru",{timeZone : "UTC", hour: '2-digit', minute: '2-digit' });
return year + "-" + month + "-" + day + " "+time
},
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);