Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

date add 1 hour javascript

//JS
function addHoursToDate(date, hours) {
  return new Date(new Date(date).setHours(date.getHours() + hours));
}

//TS
function addHoursToDate(date: Date, hours: number): Date {
  return new Date(new Date(date).setHours(date.getHours() + hours));
}

let myDate = new Date();

console.log(myDate)
console.log(addHoursToDate(myDate,2))
Comment

date add hours javascript

Date.prototype.addHours = function(h) {
  this.setTime(this.getTime() + (h*60*60*1000));
  return this;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Extract number from string javascripy 
Javascript :: remove previous datatable instance 
Javascript :: check angular version 
Javascript :: automatically scroll to bottom of page 
Javascript :: alphabet regex js 
Javascript :: ng serve host 0.0.0.0 
Javascript :: yarn create react app 
Javascript :: object to url params js 
Javascript :: how show piece of long text in javascript 
Javascript :: import react icons module 
Javascript :: javascript select element with attribute 
Javascript :: how to select html body in javascript 
Javascript :: fetch get authorization header 
Javascript :: DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify` option set to false are deprecated. See: https://mongoosejs.com/docs/deprecations.html#findandmodify 
Javascript :: javascript padstart 
Javascript :: jquery onscroll sticky header 
Javascript :: js is function 
Javascript :: react native seperator code 
Javascript :: DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. 
Javascript :: javascript move element in array to end 
Javascript :: jquery show for 5 seconds 
Javascript :: javascript change attribute 
Javascript :: jquery continue each loop 
Javascript :: jquery disable select 
Javascript :: javascript add script in head programmatically 
Javascript :: get age using moment 
Javascript :: replace class jquery 
Javascript :: JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. 
Javascript :: jquery onchange 
Javascript :: javascript check uncheck checkbox 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =