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:
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.
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?
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)