var startDate = 1582530967;
var intervalDate = moment(new Date(startDate)).add(30, 'minutes').toDate().valueOf()
console.log(intervalDate);
The above codes makes bug adding 30 minutes makes it
Monday, March 16, 2020 5:56:07 AM GMT+02:00
var startDate = 1582530967;
var intervalDate = moment(new Date(startDate)).add(30, 'minutes').toDate().valueOf()
console.log(intervalDate);
The above codes makes bug adding 30 minutes makes it
Monday, March 16, 2020 5:56:07 AM GMT+02:00
If you just want to go from timestamp to a new timestamp, just add the correct number of seconds.
var startDate = 1582530967;
var intervalDate = startDate + 30 * 60; // 30 min * 60 sec in a min
If working in milliseconds:
var startDate = 1582530967000;
var intervalDate = startDate + 30 * 60 * 1000; // 1000 ms in sec
I noticed that your startDate
variable might be in seconds when it should be milliseconds, and therefore have 3 more digits. Here is your code with slight change to get more accurate start date:
var startDate = new Date().valueOf();
var intervalDate = moment(new Date(startDate)).add(30, 'minutes').toDate().valueOf()
The code seems to correctly add 30 minutes.
Would this solve your concern?
Working sandbox: https://codesandbox.io/s/adoring-shamir-0yuxq
//using momentjs
var moment = require("moment");
//converting timestamp to date
var time = moment.unix(1368457233).format("YYYY-MM-DD HH:mm");
//adding minutes to the date
var addingMinutes = moment(time)
.add(3, "minutes")
.format("YYYY MM DD");
//converting to timestamp
var afterConversion = moment(addingMinutes).format("X");