Menu

gitpiper

addMinutesToDate javascript Code Snippet in 2024

dateintermediate

Last Updated: 16 April 2024

Calculates the date of n minutes from the given date, returning its string representation.

  • Use new Date() to create a date object from the first argument.
  • Use Date.prototype.getTime() and Date.prototype.setTime() to add n minutes to the given date.
  • Use Date.prototype.toISOString(), String.prototype.split() and String.prototype.replace() to return a string in yyyy-mm-dd HH:MM:SS format.
const addMinutesToDate = (date, n) => { const d = new Date(date); d.setTime(d.getTime() + n * 60000); return d.toISOString().split('.')[0].replace('T',' '); };
addMinutesToDate('2020-10-19 12:00:00', 10); // '2020-10-19 12:10:00' addMinutesToDate('2020-10-19', -10); // '2020-10-18 23:50:00'

javascript snippet similar to addMinutesToDate For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️