Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!