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

272
Visualizações
How to get the first day of the next month in JavaScript

I need to get the first day of the next Month for a datePicker in dd/mm/yyyy format.

how can i do it?

i have this code :

var now = new Date();
if (now.getMonth() == 11) {
  var current = new Date(now.getFullYear() + 1, 0, 1);
} else {
  var current = new Date(now.getFullYear(), now.getMonth() + 1, 1);
}

console.log(current)

but it's give this :

Sat Jan 01 2022 00:00:00 GMT+0200 

i need it like this 01/01/2022

any help here =)?

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

0

To get the first of next month:

let d = new Date();
d.setMonth(d.getMonth() + 1, 1);

Then to format as dd/mm/yyyy:

d.toLocaleDateString('en-GB');

As a runnable snippet:

let d = new Date();
d.setMonth(d.getMonth() + 1, 1);

console.log(d.toLocaleDateString('en-GB'));

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use toLocaleDateString

var now = new Date();
var current;
if (now.getMonth() == 11) {
  current = new Date(now.getFullYear() + 1, 0, 1);
} else {
  current = new Date(now.getFullYear(), now.getMonth() + 1, 1);
}

console.log(current.toLocaleDateString());

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