请有人告知我如何将选定的日期和时间更改为ISO格式,例如:
::2022年8月18日08:15
To:2022-08-18 20:15:10
我正在使用简化器。
请查找以下代码:
<script>
let simplepicker = new SimplePicker({
zIndex: 10,
});
const $button = document.querySelector('.simplepicker-btn');
const $eventLog = document.querySelector('.event-log');
$button.addEventListener('click', (e) => {
simplepicker.open();
});
const input = document.getElementById("myInput"); // <- 1) Grab the input
// $eventLog.innerHTML += '\n\n';
simplepicker.on('submit', (date, readableDate) => {
$eventLog.innerHTML += readableDate + '\n';
input.value = readableDate; // <- 2) Update the input value
});
simplepicker.on('close', (date) => {
$eventLog.innerHTML += 'Closed' + '\n';
});
</script>发布于 2022-08-18 19:53:47
.on('submit', ...回调的第二个参数是JS对象。使用它而不是readableDate来创建所需的格式。
// note that a js date called "date" is the second param to the submit callback
const date = new Date();
// truncate thru position 18 to get mm-dd-yy hh:mm:ss
// and remove the "T" that delimits the time substring
const formatted = date.toISOString().substring(0,19).replace('T', ' ')
console.log(formatted)
// now use "formatted" in the dom
// $eventLog.innerHTML += formatted + '\n';
// etc
https://stackoverflow.com/questions/73408475
复制相似问题