Auto-fill current time in correct time zone
We cannot use valueAsDate because this converts to UTC which is not desired
This commit is contained in:
parent
3bf624f9dd
commit
c1f2b0c908
18
index.html
18
index.html
@ -233,15 +233,23 @@
|
|||||||
// ------------
|
// ------------
|
||||||
// Prefill form
|
// Prefill form
|
||||||
|
|
||||||
let dateNow = new Date();
|
function dateToISOStringLocal(date) {
|
||||||
dateNow.setSeconds(0);
|
function pad(n) {
|
||||||
dateNow.setMilliseconds(0);
|
if (n < 10) {
|
||||||
|
return '0' + n;
|
||||||
|
}
|
||||||
|
return '' + n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + 'T' + pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||||
|
}
|
||||||
|
|
||||||
|
let dateNow = dateToISOStringLocal(new Date());
|
||||||
if (document.getElementById('time_birth').value === '') {
|
if (document.getElementById('time_birth').value === '') {
|
||||||
document.getElementById('time_birth').valueAsDate = dateNow;
|
document.getElementById('time_birth').value = dateNow;
|
||||||
}
|
}
|
||||||
if (document.getElementById('time_measurement').value === '') {
|
if (document.getElementById('time_measurement').value === '') {
|
||||||
document.getElementById('time_measurement').valueAsDate = dateNow;
|
document.getElementById('time_measurement').value = dateNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------
|
// --------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user