10 examples of 'javascript add hours to date' in JavaScript

Every line of 'javascript add hours to date' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
13function addHours(d, hours) {
14 var newDate = clone(d);
15 newDate.setHours(d.getHours() + hours);
16 return newDate;
17}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

10export default function addHours(time, hours) {
11 const t = new Date(time.getTime());
12 t.setHours(t.getHours() + hours);
13 return t;
14}
162add (date: Date, hours: number, dayType: Day = Day.REGULAR_DAY) {
163 this._times.push({date, hours, dayType})
164}
91addHours(hours) {
92 hours = hours || 0;
93 return this.addMilliseconds(hours * 3600000 /* Hour */);
94}
16function date_by_subtracting_hours(date, hours) {
17 return new Date(
18 date.getFullYear(),
19 date.getMonth(),
20 date.getDate(),
21 date.getHours() - hours,
22 date.getMinutes(),
23 date.getSeconds(),
24 date.getMilliseconds()
25 );
26}
3452value: function addHour(h) {
3453 var now = new Date();
3454 now.setHours(now.getHours() + h);
3455 return now;
3456}
159function addMinutes(date, value) {
160 return new Date(+date + value * 60000);
161}
50function addMinutes(date, minutes) {
51 return new Date(date.getTime() + minutes * 60000);
52}
19function hFormat(date: Date, isUTC: boolean): number {
20 return getHours(date, isUTC) % 12 || 12;
21}
7export function addMinutes(d, minutes) {
8 const newDate = clone(d);
9 newDate.setMinutes(d.getMinutes() + minutes);
10 return newDate;
11}

Related snippets