我在 HTML 中使用日期時間本地輸入型別,但我不想在輸出中使用“T”。我只想獲取日期和時間,中間有空格。
<input type="datetime-local" id="date" name="date">
輸出是:
2021-11-08T16:34
我想要的是:
2021-11-08 16:34
我需要做什么才能得到這個輸出?
PS:嘗試在沒有引導庫的情況下幫助我,因為在這個專案中我無法使用它。
uj5u.com熱心網友回復:
你可以試試這個,我用的是純javascript
//get the date
var x = document.getElementById("date").value;
//this replaces the 'T' with an space
x = x.replace("T", " ");
//this places the string back on the HTML page
document.getElementById("demo").innerHTML = x;
uj5u.com熱心網友回復:
簡單地使用.toLocaleString()方法
getDate.onclick = _ => {
dateStr.textContent = dateInput.valueAsDate.toLocaleString()
}
<input type="datetime-local" id="dateInput">
<button id="getDate">get Date</button>
<p id="dateStr">???</p>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/352855.html
標籤:javascript html
