Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
postman: How to add minutes to a dateTime while looping with JS?

I am trying to add 15 mins to a dateTime(2100-01-04T08:00:00) while looping. For each run I want to add 15 minutes , so it would be 2100-01-04T08:15:00 , 2100-01-04T08:30:00 and so on… I know I can do the below: var moment = require('moment'); moment().add(15, 'minutes').toISOString(); But this will add 15 minutes to the current moment time but I want to add 15 minutes to 2100-01-04T08:00:00.

Is this possible in postman?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can achieve this without using any third party libraries like momentJs. The default javascript Date object has methods for getting the minutes property for a date object - getMinutes() and also another method for updating this minutes property - setMinutes(). Combining them both, you can achieve your required answer.

let x = new Date('2100-01-04T08:00:00') 
for(let i = 0 ; i < 5; i ++){
  x.setMinutes(x.getMinutes()+15);
  console.log(x)
}

P.S, remove 'postman' from your question. It has nothing to do with the problem you are facing.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can easily create an addMinutes() function to add a number of minutes to a date, you can then use a while loop to loop until a specified end date is reached.

In the example below, we'll add 15 minutes to the date until the end date is reached.

function addMinutes(date, minutes) {
    let newDate = new Date(date);
    newDate.setMinutes(newDate.getMinutes() + minutes);
    return newDate;
}

let date = new Date('2100-01-04T08:00:00');
let endDate = new  Date('2100-01-04T09:00:00');

let deltaMinutes = 15;
while (date <= endDate) {
    console.log(date.toLocaleString('en-US'));
    date = addMinutes(date, 15);
}
.as-console-wrapper { max-height: 100% !important; }

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda