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

165
Visualizações
Get list of days in the week that reflect locale in JavaScript?

I have this function that returns days of the week:

var SEPARATOR = '  ';
function week_days(lang) {
    var result = [];
    for (var i = 0; i <= 6; ++i) {
        var d = new Date(1970, 1, 1 + i);
        result.push(d.toLocaleString(lang, {weekday: 'short'}).substring(0, 2));
    }
    return result.join(SEPARATOR);
}

console.log("en-us", week_days("en-us"))
console.log("pl-pl", week_days("pl-pl"))

but it's fixed and starts from Sunday like in the US locale. But in the Polish locale week starts from Monday. There are probably languages that use one or the other.

I can use new Date(1970, 1, 2 + i); and it will work, but how I can make it based on Locale? (e.g. window.navigator.language).

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

0

I've found that the spec has no way of knowing this information. It's tracked here:

https://github.com/tc39/ecma402/issues/6

This is an old issue. From the comments, it seems that there is a spec:

https://github.com/tc39/proposal-intl-locale-info

That should handle this.

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