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

132
Visualizações
Get the next Monday in a user's timezone

This post was very useful Getting the date of next Monday when it comes to figuring out how to get the next Monday in UTC time. I have the following problem.

I want to get the next Monday in user A's timezone and then convert that to user's B timezone. How can I do that?

So if user A's timezone is America/New_York and the date is January 2, 2022, I want to get the next Monday in that timezone. Then convert that date to user B's timezone. How can I do that using javascript or moment js?

The goal is to get the next availability of a user so that another user in a different timezone can set up an appointment with him.

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

0

If I'm getting your question right you want to get the date at a different time zone then get the next Monday then convert it to a time zone you want. If so this should work:

Note: this uses Moment js and moment time zone libraries. The "moment time zone with data" library is a little bulky so if you are concerned about performance then CDN might not be the way to go try node js.

function getNextMonday() {
  const now = new Date()
  const today = new Date(now)
  today.setMilliseconds(0)
  today.setSeconds(0)
  today.setMinutes(0)
  today.setHours(0)

  const nextMonday = new Date(today)

  do {
    nextMonday.setDate(nextMonday.getDate() + 1) // Adding 1 day
  } while (nextMonday.getDay() !== 1)

  return nextMonday
}

var cur_date = moment(getNextMonday());
//this gives the corrsponding date on specific time zone of next monday
console.log(cur_date.tz('America/Los_Angeles').format())
<script src="https://momentjs.com/downloads/moment.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data.js"></script>

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