1//JS
2function addHoursToDate(date, hours) {
3 return new Date(new Date(date).setHours(date.getHours() + hours));
4}
5
6//TS
7function addHoursToDate(date: Date, hours: number): Date {
8 return new Date(new Date(date).setHours(date.getHours() + hours));
9}
10
11let myDate = new Date();
12
13console.log(myDate)
14console.log(addHoursToDate(myDate,2))
1Date.prototype.addHours = function(h) {
2 this.setTime(this.getTime() + (h*60*60*1000));
3 return this;
4}