gethours
JavaScript Date getHours()方法 (JavaScript Date getHours() method)
getHours() method is a Date's class method and it is used to get the only hours from current time.
getHours()方法是Date的类方法,用于获取距当前时间仅有的小时数。
It accepts nothing as the parameter and returns a value between 0 to 23.
它不接受任何参数作为参数,并返回0到23之间的值。
Syntax:
句法:
var dt = new Date();
dt.getHours();
Examples:
例子:
Input:
var dt = new Date();
dt.getHours();
Output:
19 (if the time is 19:any_minutes:any_seconds)
JavaScript code to get the hours only from the current time using getHours() method
JavaScript代码使用getHours()方法仅从当前时间获取小时数
<html>
<head><title>JavaScipt Example</title></head>
<body>
<script>
var dt = new Date(); //Date constructor
var hours = dt.getHours(); //getting hours from current time
//printing hour
document.write("Current hour is : " + hours);
</script>
</body>
</html>
Output
输出量
Current hour is : 19
翻译自: https://www.includehelp.com/code-snippets/date-getHours-method-with-example-in-javascript.aspx
gethours