10 examples of 'moment add hours' in JavaScript

Every line of 'moment add hours' 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
91addHours(hours) {
92 hours = hours || 0;
93 return this.addMilliseconds(hours * 3600000 /* Hour */);
94}
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

13function addHours(d, hours) {
14 var newDate = clone(d);
15 newDate.setHours(d.getHours() + hours);
16 return newDate;
17}
10export default function addHours(time, hours) {
11 const t = new Date(time.getTime());
12 t.setHours(t.getHours() + hours);
13 return t;
14}
433value: function addHours(n) {
434 return this.addMinutes(n * 60);
435}
162add (date: Date, hours: number, dayType: Day = Day.REGULAR_DAY) {
163 this._times.push({date, hours, dayType})
164}
3452value: function addHour(h) {
3453 var now = new Date();
3454 now.setHours(now.getHours() + h);
3455 return now;
3456}
120convertTo24Hour( hour ) {
121 if ( 'PM' === this.amPmRef.current.value && hour < 12 ) {
122 hour += 12;
123 } else if ( 'AM' === this.amPmRef.current.value && 12 === hour ) {
124 hour = 0;
125 }
126
127 return hour;
128}
18addHours(val: number) {
19 this.value += val * 60 * 60
20}
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}
116export function makeDuration(hours) {
117 const start = moment(hours.start, ["h:ma", "H:m"]);
118 let end = moment(hours.end, ["h:ma", "H:m"]);
119
120 const startInt = parseInt(hours.start, 10);
121 const endInt = parseInt(hours.end, 10);
122
123 if (startInt > endInt) {
124 end = end.add(1, "d");
125 }
126
127 return end.diff(start, "hours");
128}

Related snippets