Add time on existing time with moment

46 views
Skip to first unread message

qwert...@gmail.com

unread,
Jan 30, 2016, 4:41:40 PM1/30/16
to nodejs
Hello all

How can i add the existing time in moment.js, Like i have Sat Jan 30 2016 17:33:43 GMT+0530 (IST) i want to add 5 minutes on it

Christopher Mina

unread,
Jan 30, 2016, 11:51:32 PM1/30/16
to nodejs
I'd suggest you don't use Moment for this purpose. Instead, you can simply parse your date into a number and then add the number of milliseconds in 5 minutes.

Eg.

var d = Date.parse({your date string});
d = new Date(d.getTime() + 300000);


see docs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime


Good luck.
Chris



Matthias Bleyl

unread,
Jan 31, 2016, 5:04:03 PM1/31/16
to nodejs
moment(<your time string>).add(5, "minutes");


Am Samstag, 30. Januar 2016 22:41:40 UTC+1 schrieb qwert...@gmail.com:
Reply all
Reply to author
Forward
0 new messages