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

341
Visualizações
What's the most reliable way to get the week day from a utc Date

This is how I'm getting the date's week day

const date = new Date('2022-06-25T'+hour+':00:00.951Z')
const day1 = date.toLocaleString('en-US', { weekday: 'short' }) 

And this is how I'm constructing the date

`${date.getUTCDate()} ${date.toLocaleString('en-GB', { month: 'short' })} ${date.getUTCFullYear()}`

But apparently fails for some dates in certain hours (this is the screenshot i was sent) enter image description here

If you notice the 25 of June and the 26 of June are actually Saturday and Sunday. So both date/day are not synced

After searching a bit online I found this implementation (that uses UTC function)

const weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
const d = new Date();
let day = weekdays[d.getUTCDay()];

And I Did this little script to compare the result for 25th of June

const weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

for (i = 0; i < 24; i++) {
   const hour = i < 10 ? '0' + i : i;
   const date = new Date('2022-06-25T'+hour+':00:00.951Z')
   const day1 = date.toLocaleString('en-US', { weekday: 'short', timeZone: 'Asia/Tbilisi' }) 
   const day2 = weekdays[date.getUTCDay()]
   console.log('2022-06-25 at', hour, day1, day2)
}

And you can see in the devtools that is not returning same day after 20h

2022-06-25 at 00 Sat Sat
2022-06-25 at 01 Sat Sat
2022-06-25 at 02 Sat Sat
2022-06-25 at 03 Sat Sat
2022-06-25 at 04 Sat Sat
2022-06-25 at 05 Sat Sat
2022-06-25 at 06 Sat Sat
2022-06-25 at 07 Sat Sat
2022-06-25 at 08 Sat Sat
2022-06-25 at 09 Sat Sat
2022-06-25 at 10 Sat Sat
2022-06-25 at 11 Sat Sat
2022-06-25 at 12 Sat Sat
2022-06-25 at 13 Sat Sat
2022-06-25 at 14 Sat Sat
2022-06-25 at 15 Sat Sat
2022-06-25 at 16 Sat Sat
2022-06-25 at 17 Sat Sat
2022-06-25 at 18 Sat Sat
2022-06-25 at 19 Sat Sat
2022-06-25 at 20 Sun Sat
2022-06-25 at 21 Sun Sat
2022-06-25 at 22 Sun Sat
2022-06-25 at 23 Sun Sat

So wat's the most reliable way to get the week day name?

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

0

const date = new Date(Date.UTC(2022, 5, 25, 3, 23, 16, 738));
const weekday = new Intl.DateTimeFormat('en-GB', {  weekday: 'short' }).format(date)

console.log(weekday)

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