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

186
Visualizações
How to get date as the local date

I am trying to get the date with timezone as TIME_ZONE = 'Asia/Shanghai'. Below the script returns the UTC time. How to convert the date as the local date?

    <script>
        var today = new Date();
        today = new Date(today.setDate(today.getDate() + 1)).toISOString().split('T')[0];
        document.getElementsByName("pickup_date")[0].setAttribute('min', today);
    </script>

  <form method="POST">
       <div>
            <label for="s2">pickup_date</label>
            <input type = 'date'  name='pickup_date' required>
         <br /><br />
        </div>
  </form>


var today = new Date();
hr=today.getHours()  #this returns the UTC date and time. I need local date and time
console.log(today);

UPDATE:

  1. actually, I have a form which needs user to input date, and this date must exclude today and past dates. Due to time difference between UTC and Beijing Time(local time/browser time), the update of excluding date will lag behind the actual local date, in 8 hours.

  2. I just found that in mobile phone browser like safari, the fobbidden date can still be chosen. how to make sure it works on mobile phone browser?

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

0

The toLocaleString function can be used for the localization of time. More information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString

var time = new Date();
var localTimeStr = time.toLocaleString('en-US', { timeZone: 'Asia/Shanghai' });
alert(localTimeStr)
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