Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda