【发布时间】:2019-08-13 17:07:34
【问题描述】:
从输入字段我得到这个值
Mon Aug 05 2019 14:29:16 GMT+0530 (India Standard Time)
如何安全地得到这部分14:29:16这是时间
【问题讨论】:
-
你有什么尝试吗?我们愿意为您提供帮助,但您最好展示您尝试过的方法和无效的方法。
标签: javascript
从输入字段我得到这个值
Mon Aug 05 2019 14:29:16 GMT+0530 (India Standard Time)
如何安全地得到这部分14:29:16这是时间
【问题讨论】:
标签: javascript
var date = new Date("Mon Aug 05 2019 14:29:16 GMT+0530 (India Standard Time)");
document.getElementById("time").innerHTML = date.getHours() + " : " + date.getMinutes() + " : " + date.getSeconds();
<!DOCTYPE html>
<html>
<body>
The content of the body element is displayed in your browser.
<h1 id="time"></h1>
</body>
</html>
【讨论】:
要获得确切的解决方案,这将起作用:
function getTime(date) {
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
return [hours, minutes, seconds].join(':');
}
【讨论】: